In my form the user can add (or remove) licence items which are generated as input nested arrays:
<div>
<select name="licences[0][type]">
<option value="">- Select -</option>
<option value="car">Car</option>
<option value="motorbike">Motorbike</option>
</select>
<input type="text" name="licences[0][car_spec]" value="">
<input type="text" name="licences[0][motorbike_spec]" value="">
</div>
<div>
<select name="licences[1][type]">
<option value="">- Select -</option>
<option value="car">Car</option>
<option value="motorbike">Motorbike</option>
</select>
<input type="text" name="licences[1][car_spec]" value="">
<input type="text" name="licences[1][motorbike_spec]" value="">
</div>
...
and here are my rules:
$rules = [
'licences.*.type' => 'required',
'licences.*.car_spec' => 'required_if:licences.*.type|car',
'licences.*.motorbike_spec' => 'required_if:licences.*.type|motorbike',
];
Now how can I ensure that the validations match the same index (*) of the licences array ?
For instance, the licences[1][car_spec] input is checked against the licences[1][type] input and not against the licences[0][type].