required_if not working

Posted 1 year ago by almost_pitt

Hey guys,

Inside of my controller, I would like to require certain inputs if something is chosen.

For example, if the number of bedrooms is 2 or more, I would like the Furnished input for bedroom 2 to be required.

Here is the code that I have tried inside of my RoomsController.php:

            'Number_of_Bedrooms' => 'required',

            'Furnished_2' => 'required_if:Number_of_Bedrooms,2',

I have also tried,

            'Number_of_Bedrooms' => 'required',

            'Furnished_2' => 'required_if:Number_of_Bedrooms,==,2',

Note: Number_of_Bedrooms is a select input and the values go from 'Studio' to '1' to '6'

This, unfortunately, does not seem to wrok. I've looked at the documentation https://laravel.com/docs/5.4/validation#rule-required-if, but haven't been able to figure it out.

Can anyone help?

Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.