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

movepixels's avatar

Dimension Validation

How do you add a custom message to the dimension validation? All I get is the generic message for both min_width, and min_height.

array (
    0 => 'The file has invalid image dimensions.',
  )

Rules:

return [
      'file' => 'required|mimes:jpeg,png,jpg|dimensions:min_width=700,min_height=500|max:3000',
      // 'width' => 'min:800|max:2000',
    ];

Messages I tried every way I can think of....

return [
    ...other rules
        'file.min_width'    => 'Please select wider image',
        'min_width'    => 'Please select wider image',
        'file.file.min_width'    => 'Please select wider image',
    ];

Anyone know how to set your own message?

Thanks, Dave

0 likes
1 reply
Zugor's avatar

You can set the validation massage of dimensions and size for an image like this

return [
    ...other rules
        'file.dimensions'    => 'Required minimum 700x500 image',
        'file.max'  => 'image size should not be more than 3000 kB'
    ];

Please or to participate in this conversation.