-
There is currently no validation rule that allows you to say that if another field is present and not empty that it's prohibited. We have kind of a unique use case, where the user can either give us their birth date (year or year + month) or they could give us an approximate age category if they are not comfortable to reveal their age. Consider the following form data [
'birth_year' => 2000,
'age_category' => '21+', // This field should not be allowed since birth year is given
] This is currently no rule that can prohibit the current field if another field has a value. The one that is closest to this is // rules
[
'age_category' => 'prohibited_with:birth_year',
] |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
There is such a rule. https://laravel.com/docs/11.x/validation#rule-prohibits |
Beta Was this translation helpful? Give feedback.
-
What about "prohibited_if"? Isn't this what you want? You put it on the field that you want to prohibit so the error appears where you want. |
Beta Was this translation helpful? Give feedback.
Did not knew about that problem, thanks, good to know.
Doesn't that mean that the general solution would be more like: ( as is shorter and more readable and should do exactly what your code does )
If not, please let me know why.