First and foremost:
- I did read both entries @ laravel and stackoverflow
I am trying to validate an array containing input[text]. They are defined currently as:
<input type='text' name='user[0][name]'/><div>@error('user[0][name]'){{ $message }}@enderror</div>
<input type='text' name='user[1][name]'/><div>@error('user[1][name]'){{ $message }}@enderror</div>
I tried the 3 variants below as well:
<input type='text' name='user[][name]'/>
<input type='text' name='name[]'/>
<input type='text' name='name[0]'/>
My ExampleController does this, in the store() method:
$validator = Validator::make($request->all(), [
'user.*.name' => 'required|string',
])->validate();
I've also tried using:
$validatedData = $request->validate([
"user.*.name" => "required|string",
]);//*/
The other option that I've tried to use to match was (for the other case):
'name.*' => 'required|string',
None of these manage to print an error message in the div that follows the input.
The only way for me to get to see the error, is if I do the validation in of the two below (for each case):
"user[0][name]" => "required|string",
"name[0]" => "required|string",
So... what is it that I'm doing wrong?