Search code examples
laravelvalidationlaravel-5.3ruleslaravel-validation

How can I add validate dimension in pixels with rules laravel?


I use laravel 5.3

My validate rules laravel like this :

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreProfileCreateRequest extends FormRequest
{
    ..
    public function rules()
    {
        return [
            'banner'=> 'required|mimes:jpeg,bmp,png,jpg|max:7024'
        ];
    }
}

I want to add validate dimensions in pixels. So if user not upload banner with dimension 1170 x 300 pixels there exist message like this :

Please upload an image with 1170 x 300 pixels dimension

How can I add the validate on the rules?


Solution

  • Please refer to documentation here: https://laravel.com/docs/5.3/validation . "Dimensions" section.

    You just will need to use similar to this.

    'avatar' => 'dimensions:min_width=100,min_height=200'