I have a form in which a user can add as many contacts as he'd like. But I get stuck on the validation for this. I use the old way of validating forms, using the $request->validate
method.
My form (part of it that is relevant):
<div class="row">
<div class="col">
{!! Form::text('contact_name[]', __('site.contact.name'))->placeholder(__('site.contact.name'))->help('<a href="#add-contact" id="add-contact">+ ' . __('site.contact.add_person') . '</a>') !!}
</div>
<div class="col">
{!! Form::text('contact_email[]', __('site.contact.email'))->placeholder(__('site.contact.email')) !!}
</div>
<div class="col">
{!! Form::text('contact_phone[]', __('site.contact.phone'))->placeholder(__('site.contact.phone')) !!}
</div>
</div>
And my validation is in the CRUD store method:
$request->validate([
'contact_name.*' => 'required|max:255',
'contact_email.*' => 'required|email|max:255',
'contact_phone.*' => 'required|max:255',
]);
This always results in a pass, while there is nothing in the input. When I try the following; it always fails.
$request->validate([
'contact_name[]' => 'required|max:255',
'contact_email[]' => 'required|email|max:255',
'contact_phone[]' => 'required|max:255',
]);
According to the documentation, the wildcard way, is the way it should be. Any ideas on how to get this working?
Kind regards, Niels
-- EDIT 1 --
My form request data looks like this (only relevant variables included)
"_token" => "IbYI2FYivl30YJfw8hBHti9bsaBUdkG2T76HZOIN"
"contact_name" => array:1 [▼
0 => "abc"
]
"contact_email" => array:1 [▼
0 => "abc"
]
"contact_phone" => array:1 [▼
0 => "abc"
]