-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Change of behaviour in Validation between Laravel 5.4.12 and 5.4.22 #19140
Comments
There were changes to validation to account for edge cases in 5.4.16. See #18376. Since the definition of 'required' according to the Laravel docs includes "the field must not be empty" and the field is considered empty if "the value is null", then required|nullable doesn't really make sense (even though it used to work). Seems like maybe I'll be honest though, validation can be one of the most confusing things to work with, especially with edge cases, so maybe @themsaid can clear things up for you. |
Thanks @devcircus, I completely missed that the I agree that this is confusing, especially having it change behavior between minor versions. One might think that |
This area became very complicated and I don't see it possible to cover all scenarios around this edge case, the changes that were made were based on dozens of bug reports which implied the behaviour you're describing as a bug :) I'd say you use the I'm closing this issue but continuing to follow the issue so feel free to ping me whenever you need. |
Thanks for the update @themsaid, I did exactly that, replaced the validations with In any case I consider this fixed, it was just an opinion on the wording about the rules and the (in my opinion) sensible meaning of the word required, but I totally agree that this is a matter of taste and that some people would think that Thanks! |
Description:
If we want to validate a field with
null
as valid input but we also want it to berequired
, we would use a rule such asrequired|nullable|whatever
which worked as expected in Laravel 5.4.12 but stopped working in Laravel 5.4.22.Steps To Reproduce:
Running the following code I would expect
fails()
to befalse
, as therequired
rule passes given that the attribute is present, and thenullable
rule passes given that the value is null.The text was updated successfully, but these errors were encountered: