I have laravel FormRequest which prepares rules for validation. I have dumped prepareForValidation function at the end and it shows dump immediately, but when I try to call $request->validation()
function in controller it takes too long. I have validations like required|numeric|max:999999.99|min:0|email
. When I send 1000 items which holds for each item almost 45 fields.
There is not any actions before this validation from my code side. Is there any solution to handle this kind of things? Requests sends via API.
Laravel validation is slow with large arrays. I have sent an issue and PR to Laravel for fixing it. My PR was not accepted. What you can do now before fixing Laravel:
$request->validate(['array' => 'required|array|max:100']);
$request->validate(['array.*' => 'required|numeric|max:1000']);
collect($request['array'])->chunk(100)->each(function (array $chunk) {
Validator::validate(
['array' => $chunk],
['array.*' => 'required|numeric|max:1000']);
});