I'm making a Laravel app and have a form that users can add input fields to with javascript. The form therefore has multiple inputs with the same name.
e.g. <input name='date[]' class='form-control' ...
In the update action in my controller I can loop through the inputs and update my database without any issues. The problem is when I try to add validation.
I have tried using the validate method provided through Controller ValidatesRequest trait..
$this->validate($request, ['date.*' => 'required']);
but I receive this error:
ErrorException in helpers.php line 519 "htmlspecialchars() expects parameter 1 to be string, array given"
I then followed approved answer in this post: here
so in my controller I manually created a validator like so:
$validator = Validator::make($request->all(), ['date.*' => 'required']);
when I dd($validator->messages()); I can see that the validations are being hit and the messages are generating correctly but when I go to send those error messages to my view like this:
if($validator->fails()) {
return redirect()->back()
->withErrors($validator)
->withInput();
}
I get the same error as before:
ErrorException in helpers.php line 519 htmlspecialchars() expects parameter 1 to be string, array given
I have read Laravel docs on validating arrays (a short section), and have tried googling my problem w/o success. Any help would be much appreciated.