1 year ago

Validation of multiple inputs in array

Posted 1 year ago by michaelw1025

I am trying to use Laravel's validation to validate an input array. It is very tough to explain so hopefully the code is useful.

In Blade View

@foreach($dependants as $dependant)
    <input type="text" name="dependant[{{$loop->index}}][name]"  value="{{ old('dependant.'.$loop->index.'.name' )}}">

In validation

    'dependant.*.name' => 'required',

The problem is that when the form is submitted and validation fails, I get an error message shown for all the inputs, even if a value was given. The error messages show up on the correct input and have the correct input name, but show up whether they should or not. Thank you for any help.

Please sign in or create an account to participate in this conversation.