Required_if laravel with multiple value Required_if laravel with multiple value php php

Required_if laravel with multiple value


You just have to pass all the values as parameters separated by comma:

$rules = array(      'selection' => 'required',      'stext'     => 'required_if:selection,2,3');


EDIT:As pointed out by LePhleg answer, there is a nicest syntax for this validation:

$rule = array(  'selection' => 'required',  'stext' => 'required_if:selection,2,3,);

Old answer below:

I think that the require_if validation accept only one value per time.Try to change your validation code as below:

$rule = array(  'selection' => 'required',  'stext' => 'required_if:selection,2|required_if:selection,3',);

EDIT:Check LePhleg answer, is more cleaner.At the time of the answer that was not possible, just check the question, he was using the same method but not worked.


try this one

if single match value then used like that

'stext'     => 'required_if:selection,2'

if you have multiple value then used like that (separated by comma)

'stext'     => 'required_if:selection,2,3'

for more information see documentation required_if