Shree krishna lamichhane
Shree Krishna Lamichhane

Follow

Shree Krishna Lamichhane

Follow
Image Dimension Validation in Laravel from Controller

Image Dimension Validation in Laravel from Controller

Shree krishna lamichhane's photo
Shree krishna lamichhane
·Feb 4, 2022·

1 min read

Here's a quick validation rules for image dimension in Laravel

public function postImage(Request $request)
    {
        $this->validate($request, [
             'avatar' => 'dimensions:min_width=250,min_height=500'
        ]);

        // or... 

        $this->validate($request, [
             'avatar' => 'dimensions:min_width=500,max_width=1500'
        ]);

        // or...

        $this->validate($request, [
             'avatar' => 'dimensions:width=100,height=100'
        ]);

        // or...

        // Ensures that the width of the image is 1.5x the height
        $this->validate($request, [
             'avatar' => 'dimensions:ratio=3/2'
        ]);
    }

Happy Coding !

 
Share this