Posted inTechnology / Laravel / Programming

Laravel 5.7 Image File Validator Validation

Today, We want to share with you Laravel 5.7 Image File Validator Validation.In this post we will show you Laravel 5.7 file upload size validation, hear for Check File Size & Extension Uploading Using Laravel we will give you demo and example for implement.In this post, we will learn about How to add custom Laravel 5.7 validation for image file upload with an example.

Laravel 5.7 Image File Validator Validation

There are the Following The simple About Laravel 5.7 Image File Validator Validation Full Information With Example and source code.

As I will cover this Post with live Working example to develop Image Validation in Laravel 5.7 Example, so the Laravel 5.7 Image Upload with Validation for this example is following below.

Image Validation in Laravel 5.7 Example

  • validation must be an image
  • MIME type image/jpeg
  • file size in kilobytes
  • Check dimensions

Here simple Laravel 5.7 Rules for Custom Validation Rules for Images and Photos.

Rule 1. image

an image Like (jpeg, png, bmp, gif, or svg

Probably the most simple straightforward one:

public function rules()
{
    return [
        'profile_photo' => 'image',
    ];
}

Rule 2. mimes

Laravel: validate file types

MIME type image/jpeg

public function rules()
{
    return [
        'profile_photo' => 'mimes:jpeg,png',
    ];
}

Rule 3. size

Check file size in kilobytes for Laravel 5.7 file upload size validation Example

public function rules()
{
    return [
        'profile_photo' => 'image|size:1024', // 1 MB
    ];
}

Rule 4. dimensions

restrict min/max width/height

public function rules()
{
    return [
        'profile_photo' => 'dimensions:min_width=100,min_height=100,max_width=1070,max_height=1070', 
    ];
}

would Like cover Images 600×400 and 300×200

public function rules()
{
    return [
        'photo' => 'dimensions:ratio=3/2', 
    ];
}

Laravel Rule : combine width+height+ratio

use Illuminate\Validation\Rule;

Validator::make($data, [
    'avatar' => [
        'required',
        Rule::dimensions()->maxWidth(1070)->ratio(3/2),
    ],
]);
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Image File Validator Validation.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype