-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird numeric constraint behaviour #37529
Comments
Might be the "ConvertEmptyStringsToNull" middleware that runs by default in Laravel applications. You should be able to remove that from the kernel.php and get the result you want. However, you may want to rethink the logic, as converting empty strings to null is the most common way of handling empty strings in form submissions. |
Hi @devcircus , sorry but your suggestion is actually a workaround for sourcing data from a request. The question is about validation and constraints so doesn't matter where the data comes from. |
So the way the validator works is that it'll allow the data to pass when it's not "required". You aren't requiring $v->make(['empty' => ''], ['empty' => 'required|numeric'); |
Hi @driesvints , thanks for the response. However, it's far from obvious behavior and must be clearly stated. Moreover, it doesn't work and doesn't provide the required (and mentioned in docs) behavior:
|
@SCIF in that case you need to add the nullable rule as well. We definitely welcome prs to the docs if you think something can be more clear 👍 |
Hi @driesvints , I checked that behavior before filing this issue:
|
I'm sorry but that looks good to me. Like I said if any is unclear feel free to send in a pr to the docs. |
So there is no way to be sure whether a field has value of |
Sorry, but I don't really understand how to explain that check for |
Or may be |
I'm having the same issue. The problem goes all the way to #18376, 4.5 years ago. Before v5.4.16, nullable would override implicit rules (required*, present, filled, accepted), but now it does not. In order to solve this, I used this stack overflow answer to extend the Validator and remove the "is implicit" check from
If you still want to be able to omit the field entirely, change |
Description:
A quote from https://laravel.com/docs/8.x/validation#rule-numeric
So when I supply a value
''
I'm expecting to have a failure as none of rules are met.Steps To Reproduce:
The text was updated successfully, but these errors were encountered: