0
votes

Curious if there is a simple way to do this.. Lets say for example I have a radio input that asks something like:

Do you own a car? (y) (n)

If yes is answered, then it would ask something like:

What type of car do you own?

Question would be - if I setup validation in Laravel, would I be able to set a rule stating that "What type of car do you own?" is only required if "Do you own a car" is selected as yes?

The way I envision this to be, within the public function rules, I'd have a conditional there, stating that if selected is yes, then return these rules. But if I have a form with over 80 fields, some of them will be required regardless of the conditionals, where some are conditional based. What would be the cleanest way I can pull this off without having to repeat the same rules under multiple if/else statements?

1
I'd advise you do this on client side. Javascript (JQuery maybe) - Michel
Doing this as well, but am asked to also do it server side. - lpangm03

1 Answers

1
votes

Answering my own question here:

required_if:field,value,...

The field under validation must be present if the field field is equal to any value.