0

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?

2
  • I'd advise you do this on client side. Javascript (JQuery maybe) Commented Jul 22, 2016 at 15:31
  • Doing this as well, but am asked to also do it server side. Commented Jul 22, 2016 at 15:33

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.