Level 1
Found the solution:
in AppServiceProvider boot() method:
Validator::extend('square_image', function($attribute, $photo, $parameters){
list($width, $height) = getimagesize($photo);
return ($width == $height);
});
Hi Everyone,
My task is to upload images to a server and I have a custom rule - every image should be squared. The user allowed to upload 200x200, 800x800 like images but not allowed to upload a 450x320 image. I'd like to create a square_image validator but can't figure out what is the best approach to do it.
I'd like to use it in my controller like this:
$this->validate($request, [
'file' => 'required|square_image|mimes:jpg,jpeg,wav'
]);
Found the solution:
in AppServiceProvider boot() method:
Validator::extend('square_image', function($attribute, $photo, $parameters){
list($width, $height) = getimagesize($photo);
return ($width == $height);
});
Please or to participate in this conversation.