In my Laravel app, I am creating a dynamic search functionality using Eloquent and I have a customer search form which looks like this:
customers.search.blade.php Contrived Example
<form method="post" action="{{ route('customers.search') }}">
@csrf
<div class="form-group">
<label for="first_name" class="font-weight-bold">First Name</label>
<div class="input-group">
<div class="input-group-prepend">
<select name="first_name['operator']" class="custom-select">
<option value="%">%</option>
<option value="=">=</option>
<option value="!=">!=</option>
</select>
</div>
<input id="first_name" name="first_name['query']" type="text" class="form-control">
</div>
</div>
</form>
I have a SearchCustomerRequest (FormRequest) class which builds out the validation rules dynamically. I've dumped it, so you can see what the generated rules looks like:
In my CustomersController under search method, I did the following to see what the validated request array looks like:
class CustomersController extends Controller
{
// ...
public function search(SearchCustomerRequest $searchCustomerRequest)
{
dd($searchCustomerRequest->validated());
}
// ...
}
In order to test this, in the search form, I've selected the firstname['operator'] to % and typed the first_name['query'] to test and submitted the form.
I got the following response (i.e. empty array):
[]
So, I dumped the whole request object $searchCustomerRequest to see what was in the parameter bag and this is what I see:
As you can see, my request is valid and my rules also looks correct, yet the validation doesn't seem to be working as expected.
Any ideas what might be wrong here?

