vati22's avatar

Multiple images upload mimetype problem

Hello, 5.2 - When Im uploading multiple files, mime error doesnt work , errorBag is empty. It works fine on single file upload.

public function rules()
{
    $rules = [];

    if(count($this->file('images')) > 0){
        foreach($this->file('images') as $key=>$img){
            if($img != null){
                $rules['images.'.$key] = 'mimes:png,jpeg';
            }
        }
    }


    return $rules;

}
0 likes
3 replies
Devmaurice's avatar

With 5.2 you can use

$rules = [          
            'images.*' => 'mimes:png,jpeg',           
        ]

this will validate all images .

check matt Stauffer tutorial tutorial

vati22's avatar

@Devmaurice Ive tried * but cant see error message for example : The images.0 must be a file of type: png, jpeg..

every other error messages work. But with multiple array errorBag is empty if checking mimes.

vati22's avatar
vati22
OP
Best Answer
Level 3

Solution is to add protected variable in request

protected $dontFlash = ['images']

Please or to participate in this conversation.