jeudi 30 août 2018

Laravel Validation depending on the value of field

Let's say I have a combo box with some values

<option value="0">All</option>
<option value="1">ABC</option>
<option value="2">PQR</option>
<option value="3">XYZ</option>

My validation is as follows

'dept_id' => 'required|exists:department,id'

As you can see I want the dept_id field to be the id that exists in department table id column but my first option is "All" whose id obviously does not exists in department table.

So how can I ignore the exists rule if value=0 in Laravel 5.6 ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire