-
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
[5.3] Validation: rules with "required" continue to evaluate #15084
Comments
In 5.2 if an attribute was null, empty string, or empty array it would pass all other validation rules, for example this would pass:
That's acceptable in case the data is coming from HTML, in which an empty field would result an empty string value, but since validation is also used to validate arrays an API request might have a value as an empty string, empty array, or null that shouldn't pass such check. For this we added a To stop validation when
This will prevent running any further checks after the |
@themsaid thank you very much for clearing that up! In fact I'm using validations for a API-only project and yes, the I see that Basically, Can you confirm this for me? I'm happy to make a PR for the Upgrade Notes because I couldn't find any reference for this. |
Actually in 5.2 even if you didn't use But be careful that bail will always run the first rule, so |
Thanks and understood. So basically |
Sure, though Laravel doesn't follow semver. We always have breaking changes in minor releases. |
Fine by me, I just wanted to state it explicitly and have it confirmed so it's good to go for the upgrade guide which doesn't mention it. |
👍 |
It really to me seems like if the |
I share this sentiment. I can't come up with a use-case where I would want |
Working on changing that. |
That's pretty awesome, thanks everyone here and especially for @themsaid for fixing and (and ofc @taylorotwell for ... ya know, the framework and all 😄 ) |
When a validation rule contains
required
, it will not stop evaluating further rules. This is really a problem/break with previous versions when using custom validation which, until now, could always expect that the value they're passed fulfills therequired
rule (i.e. it's not something "nully", "empty", etc.).Example with 5.2:
Example with 5.3.4:
The
NULL
form thevar_dump($val)
should never have happened and theurl
validator should not have been called.Why are further rules called, when the value did not match the
required
criteria?The text was updated successfully, but these errors were encountered: