Description
In the Eloquent package, the Number
field only accepts an integer or float. This is correct for JSON because a JSON number decodes to a PHP integer or float.
However, Laravel's integer
and numeric
validation rules pass with a string that represents a number - because Laravel's validation is loosely-typed. This means that a string number value can pass the validation but then cause an exception to be thrown from the Number
field.
We should fix in two ways:
-
Provide a
number
validation rule that can be used for a JSON number - ensuring the PHP value is validated as either an integer or float. This should be the recommended way of validating the number field. -
We could provide a
acceptStrings()
method on the number field - when called, the field would also accept a numeric string. Personally I wouldn't use this but it would mean the developer can opt-in to numeric strings.