Last active
March 5, 2018 08:37
-
-
Save voeurnchy/53ae824e6f78a28fc33c5e4d3ad00d3e to your computer and use it in GitHub Desktop.
validation of image and countrycode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add into AppServiceProvider::register() | |
Validator::extend('imageable', function ($attribute, $value, $params, $validator) { | |
try { | |
ImageManagerStatic::make($value); | |
return true; | |
} catch (\Exception $e) { | |
return false; | |
} | |
}); | |
Validator::extend('countrycode', function ($attribute, $value, $params, $validator) { | |
return in_array(strtoupper($value), array_keys(Codes::$countries)); | |
}); | |
//================// | |
// Usage // | |
//================// | |
$this->validate($request, [ | |
'avatar' => 'imageable', // allow base64, all image type, averyting that can be an image. | |
'country_code' => 'countrycode' | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment