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.

Read Also:  How to Configure Virtual Host in XAMPP

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

Read Also:  How to get all products in WooCommerce

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 :

Read Also:  JavaScript Access PHP variables in jQuery

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Image Upload Validation Tutorial
  2. Read Also:  Create React Nested Router component
  3. Read Also:  Angular DataTable Pagination Searching Sorting in PHP
  4. Read Also:  store all record using laravel Cache Example
  5. Read Also:  Laravel File Upload Validation Rules Example
  6. Read Also:  How to Open URL in New Tab using CSS
  7. Read Also:  Send email using nodejs and express in Nodemailer steps
  8. Read Also:  jQuery Form Validator Script
  9. Read Also:  how to get radio button value using jquery?
  10. Read Also:  PHP Laravel 5.7 Image Upload with Validation Tutorial Example
CLOSEX