joedawson's avatar

Validation on a multiple file upload

Hello all,

I have my request set up, I'm trying to apply some validation to my file input that allows for multiple uploads.

{{-- Photo(s) --}}
<div class="form-group">
    {!! Form::label('photos', 'Photo(s):') !!}
    {!! Form::file('photos[]', ['multiple']) !!}
</div>

With the following rules in my request.

public function rules()
{
    return [
        'females'   => 'required',
        'photos[]'  => 'required|image'
    ];
}

And some custom messages.

public function messages()
{
    return [
        'females.required'  => 'You must select at least one female.',
        'photos[].required' => 'You must select at least one photo before attempting to upload.'
    ];
}

Now when I try to upload a file - or multiple - it always throws the required validation? Why?

Does Laravel's validation not work for multiple file fields?

0 likes
3 replies
jekinney's avatar

Remove the brackets in your photo validation.

jekinney's avatar

The brackets throw an error in a select array in validation.

Could try it in a for each loop.

Please or to participate in this conversation.