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

Tithira's avatar

Image Validation multiple ratios

I am validating my images and i want to accept multiple ratios ( 3/2, 4/3, 16/9 ) , i have tried validating like this

'uploadImage' => 'sometimes|image|mimes:jpeg,png,jpg|max:10240|dimensions:ratio=4/3,ratio=3/2,ratio=16/9',

It only validates my last argument, and fails the rest of the ratios, how to achieve this ? Any help is appreciated

0 likes
3 replies
bobbybouwmann's avatar
Level 88

You need to make a custom rule to achieve this. Right now it's not possible to check against multiple dimensions as far as I know.

An alternative is using the min_height

'uploadImage' => 'dimensions:max_width=300,max_height=200,

Documentation: https://laravel.com/docs/7.x/validation#rule-dimensions

I would personally create a custom rule that supports this syntax: https://laravel.com/docs/7.x/validation#custom-validation-rules

1 like
Tithira's avatar

Thanks a lot for the help, i used a closure to validate and works great.

Please or to participate in this conversation.