An Laravel 5 Serviceprovider for ImageValidationRules
A German Blog post about this ServiceProvider can be found here.
- Laravel >5.0
- Intervention Image
- Install Intervention Image (e.g. via composer) and register it's ServiceProvider and Alias in app/config.php
- Download ImageValidationServiceProvider.php and copy into your App/Providers directory
- Register the ServiceProvider
$providers = [
'App\Providers\ImageValidationServiceProvider',
...
];
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',
];
}
}
The following rules are implemented:
- width_larger
- width_smaller
- width_equal
- height_larger
- height_smaller
- height_equal
- ratio_larger
- ratio_smaller
- ratio_equal
Feel free to give feedback or ask for more validation rules.