Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required_if laravel with multiple value

I have a dropdown menu like this:

<select name="selection">    <option value="1">Option 1</option>    <option value="2">Option 2</option>    <option value="3">Option 3</option> </select> <input type="text" name="stext"> 

I want the following in laravel:

public static myfunction(){    $input = \Input::only('selection','stext');    $rule = array(       'selection' => 'required',       'stext' => 'required_if:selection,2,3',    );    $validate = \Validator::make($input,$rule); } 

But if I select option 1, stext is still required. Why? How can I fix it?

like image 940
Donny Akhmad Septa Utama Avatar asked Mar 29 '16 03:03

Donny Akhmad Septa Utama


1 Answers

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

$rules = array(       'selection' => 'required',       'stext'     => 'required_if:selection,2,3' ); 
like image 77
lephleg Avatar answered Sep 24 '22 11:09

lephleg