Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
500 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...