Posts Learn Components Snippets Categories Tags About
/

Laravel Image validation Rule

Learn how to define laravel image validation rule

Created on Aug 02, 2021

10 views

To validate the image file in Laravel you can specify the rule inside the validator "method()". Inside the validate method you can define the validator necessary for the image like below.
<?php

Route::post('/image-upload', function (Request $request) {
    $request->validate([
        'image-upload' => 'required|image|mimes:jpeg,png,jpg|max:1024',
    ]);
});

To get the dimension you can define it as follows (maximum width 1080px and height 600px).
'image-upload' => 'dimensions:max_width=1080,max_height=600'

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Laravel Image validation Rule

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More