Skip to content

luke-nehemedia/laravel-image-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Laravel Image Validation (ServiceProvider)

An Laravel 5 Serviceprovider for ImageValidationRules

A German Blog post about this ServiceProvider can be found here.

Requirements

Installation

  1. Install Intervention Image (e.g. via composer) and register it's ServiceProvider and Alias in app/config.php
  2. Download ImageValidationServiceProvider.php and copy into your App/Providers directory
  3. Register the ServiceProvider
$providers = [
    'App\Providers\ImageValidationServiceProvider',
    ...
];

Example

I recommend highly to use Requests for form validation in Laravel 5. More details on using those Requests can be found in the Laravel Documentation.

This example shows a request that validates an image to be quadratic with a with and height of minimum 500px.

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class TestRequest extends Request
{

    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'grafik'     =>  'image|ratio_equal:1|height_larger:499|width_larger:499',
        ];
    }
}

Documentation

The following rules are implemented:

  • width_larger
  • width_smaller
  • width_equal
  • height_larger
  • height_smaller
  • height_equal
  • ratio_larger
  • ratio_smaller
  • ratio_equal

Feedback

Feel free to give feedback or ask for more validation rules.

About

An Laravel 5 Serviceprovider for ImageValidationRules

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages