Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Laracast13's avatar

laravel validate attach image number

How check validate attach image number ?

        $request->validate([
           'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048',
        ]);
0 likes
9 replies
srasch's avatar

Hey.

I think, you need two validations here:

$request()->validate([
    'image' => 'max:5', // check the length of the array
    'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048', // checks file size, type etc.
]);

srasch's avatar

Did you copy that 1:1? Because i made a mistake.

Here is the correct version:

$request->validate([
    'image' => 'max:5', // check the length of the array
    'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048', // checks file size, type etc.
]);

Do you get an errors when validatiing your input?

MichalOravec's avatar
Level 75

Why image.*.*?

$request->validate([
    'image' => 'array|min:1|max:5',
    'image.*' => 'mimes:jpeg,jpg,png,gif|max:2048'
]);
1 like
Laracast13's avatar

Why image.*.*? -I use this

   <input type="file" id="image" name="image[1][]" class="form-control" multiple>
   <input type="file" id="image" name="image[2][]" class="form-control" multiple>

find solution

           'image.*' => 'max:30', 
           'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048',
MichalOravec's avatar

@www888 The id attribute has to be unique.

By the way I gave you a correct solution, it was just without one level.

1 like
Laracast13's avatar

it must be like this ?

 'image.*' => 'array|max:2', 
MichalOravec's avatar

In your case yes, I added array validation rule to be clear that you have an array.

Please or to participate in this conversation.