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