tanmay_das
1 year ago

Laravel multi file validation fails

Posted 1 year ago by tanmay_das

I have a multiple file input field:

<input type="file" id="documents" name="documents[]" multiple>

In ProjecRequest:

    $rules = [
      'documents.*' => 'mimes:doc,pdf,jpeg,bmp,png|max:20000',
    ];
    return $rules;

In [email protected]:

    public function store(ProjectRequest $request)
    {
       $project = Project::create([
         /*key=>value removed to keep the question clean*/
       ]);

       foreach ($request->documents as $document) {
           $filename = $document->store('documents');
           Document::create([
              'project_id' => $project->id,
              'filepath' => $filename
           ]);
       }
       return redirect()->back();
    }

But when I try to upload a png or pdf I get the following validation error:

The documents.0 must be a file of type: doc, pdf, jpeg, bmp, png.

Please sign in or create an account to participate in this conversation.