|string> */ public function rules(): array { $config = config('fileupload'); return [ 'f' => [ 'required', 'array', 'max:' . $config['max_files_per_upload'], ], 'f.*' => [ 'required', 'file', 'max:' . $config['max_file_size'], // in KB new MimeTypeRule($config['allowed_mimes']), ], ]; } /** * Get custom messages for validator errors. */ public function messages(): array { $config = config('fileupload'); return [ 'f.required' => 'Please select at least one file to upload.', 'f.array' => 'Invalid file upload format.', 'f.max' => 'You can upload a maximum of ' . $config['max_files_per_upload'] . ' files at once.', 'f.*.required' => 'One or more files are missing.', 'f.*.file' => 'One or more uploads are not valid files.', 'f.*.max' => 'One or more files exceed the maximum size of ' . $config['max_file_size'] . 'KB.', ]; } /** * Handle a failed validation attempt. */ protected function failedValidation(Validator $validator) { Log::warning('File upload validation failed', [ 'ip' => $this->ip(), 'errors' => $validator->errors()->toArray(), 'has_files' => $this->hasFile('files'), 'all_input' => array_keys($this->all()), ]); parent::failedValidation($validator); } }