$item) { $validator = Validator::make($item->toArray(), $rules, $messages); if ($validator->fails()) { $errors[$index + 1] = [ 'index' => $index + 1, 'errors' => $validator->errors()->all() ]; } if ($additional) { $error = call_user_func($additional, $item); if ($error) { $errors[$index + 1] = [ 'index' => $index + 1, 'errors' => $error ]; } } } if ($errors) { throw new \App\Exceptions\ValidationException(errors: array_values($errors)); } } }