bajki's avatar
Level 1

Multiple file validation when uploding pdf and image

Hi, how to make validation if i upload two files, let's say pdf and image, and for image i want use max:400 and dimensions:min_width=300,min_height=300,max_width=1600, and for pdf max:8000.

Now i have : 'files.*' => 'required|file|max:400|dimensions:min_width=300,min_height=300,max_width=1600'

But this won't work with pdf.

Thanks.

0 likes
1 reply
kevinbui's avatar

You might want to try some complex conditional array validation:

$validator->sometimes('files.*', 'dimensions:min_width=300,min_height=300,max_width=1600', function ($input, $item) {
    return in_array($item->getClientOriginalExtension(), ['jpg', 'jpeg', 'png']);
});

$validator->sometimes('files.*', 'max:8000', function ($input, $item) {
    return $item->getClientOriginalExtension() == 'pdf';
});

Please or to participate in this conversation.