vendredi 28 octobre 2016

How to set require if value is chosen in another multiple choice field in validation of laravel?

I have a form like this:

<input type="checkbox" name="category[]" value="a">Option A</option>
<input type="checkbox" name="category[]" value="b">Option B</option>
<input type="checkbox" name="category[]" value="c">Option C</option>
<input type="checkbox" name="category[]" value="d">Option D</option>
<input type="checkbox" name="category[]" value="e">Option E</option>
<input type="checkbox" name="category[]" value="f">Option F</option>

<input type="text" name="description">

If option A is chosen, I want to make description required in backend validation in laravel 5. So I tried:

$validator = Validator::make($request->all(), [
        'description' => 'required_if:category,a',
    ]);

if ($validator->fails()) {
        return "error!"
}

However, the checking is not working. How should I set the validation rule to make it works?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2eWHZj6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire