user3573738
user3573738

Reputation:

How to validate array of files?

I use this validation rule:

 $validator = Validator::make($request->all(), [
        'file' => 'required|file|max:100000',
    ]);

Template is:

   {!! Form::file('file[]', []) !!}

I tried to send files[] as array, but my validation rule does not work

Upvotes: 2

Views: 70

Answers (1)

Tim Lewis
Tim Lewis

Reputation: 29278

That's not how array validation works. When you're sending files[], you need to check that files is an array, and files.* values are valid file with a max size:

$validator = Validator::make($request->all(), [
    'files' => 'required|array',
    'files.*' => 'file|max:100000',
]);

{!! Form::file('files[]', []) !!}

Note: You input name should match the pluralization of the noun being passed. file is singular, and suggests a single file, files is plural and suggests multiple files.

Upvotes: 2

Related Questions