I have a form with an input which allows to upload PDFs.
Here is the method that validates my input :
protected function validator(array $data)
{
return Validator::make($data, [
'title' => 'required|max:255|string',
'artist' => 'required',
'notes' => 'nullable|string',
'file' => 'required|mimes:pdf|max:500',
'g-recaptcha-response' => 'required|captcha',
]);
}
The rules are working for all the other fields, but it does not work for the file input. Whatever I upload, PDF or not, I have the following error :
The file must be a file of type: pdf.
I just solved my issue.
In case someone has the same problem, you need to set the enctype
attribute of your form to multipart/form-data
.
In short, something like this :
<form action="#" enctype="multipart/form-data">
...
</form>
The error is not very clear, so I hope this helps.