New "switch" validation rule #48004
Replies: 3 comments 4 replies
-
Not a big fan of the idea. as the validation is a way to prevent garbage data. Why would you turn it off for your site? it's not likely your site will send in something else than a date, as per your example. Or give me a real life use case that makes more sense than this. also, why handling this with a query parameter? I could be a partner. I could just want to enter a datetime there without going through the hassle of modifying it's format and then ommit 'withValidation'... |
Beta Was this translation helpful? Give feedback.
-
Is this the case to use sometimes? |
Beta Was this translation helpful? Give feedback.
-
Something like I see use-case for this in terms of premium users, but in general, not only switching off. Like, if you a premium, you have a max of 20, otherwise 10. As it sounds, so it is writen: $rules = [
'phone' => 'bail|required|digits:11|starts_with:7',
'code' => some_conditions() ? 'required|string|digits:4' : 'sometimes',
]; |
Beta Was this translation helpful? Give feedback.
-
Sometimes I need to turn off form validation rules.
This can be done by adding several "if". However, this adds a lot of code.
I am using an another way.
See:
If
withValidation=true
is passed in a query, then the validation rules are used.If
withValidation
is not present, all validation rules for this field are ignored.The "switch" is controlled via the middleware:
In our company, we enable validation for partners API and disable it for the site API.
If you like the idea, I'll make a pull request.
Beta Was this translation helpful? Give feedback.
All reactions