laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Proposal] Strict validation for integer and boolean validation rules #2145

Open tonysm opened 4 years ago

tonysm commented 4 years ago

Validation rules like integer and boolean, for instance, allow passing string values to them. I had a use case to only allow strict types (I'm storing IoT configurations that will be sent to the device, and the parser at that end complains when "integer" values aren't real integers").

Suggestion

We could add a strict flag on those validation rules, like: integer:strict and boolean:strict that would also check for strictness using is_integer and is_bool.

Thoughts?

halaei commented 4 years ago

My suggestion is to introduce a general rule type:... where type can be one or many of array, object, string, integer, number, bool, null. Also some alternative for in rule like Rule::strict(true, false).

See https://github.com/justinrainbow/json-schema/blob/master/src/JsonSchema/Constraints/TypeConstraint.php