#boolean validation accepts 0 & 1 ints.

6 messages · Page 1 of 1 (latest)

junior falcon
#

The boolean rule ex:

$validator = Validator::make($data, [
  "is_public" => ["required", "boolean"],
  //...
]);

$validator->validated(); // is_public can be type int, 0 or 1.

accepts JSON {"is_public": 0}
The validated array can have ints, and possibly other types I haven't discovered yet.

Is there a nice way to validate + ensure the is_public field is type boolean?

#

Is it all the same when it's saved to the DB?

#

maybe that's why laravel does this

rigid juniper
#

0 1 and true / false both eval as boolean

junior falcon
#

yes but I think it'd be nice to get a boolean if I validate that it's a boolean

rigid juniper
#

ya I guess their boolean is more just "truthy" than cast