-
-
Save iammart/96ac93cf26623fd571f0f3cbdcdd3fdd to your computer and use it in GitHub Desktop.
A extensions validation rule for Laravel 5
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 | |
// For example in AppServiceProvider | |
Validator::extend('extensions', function ($attribute, $value, $parameters) { | |
return in_array($value->getClientOriginalExtension(), $parameters); | |
}); | |
Validator::replacer('extensions', function($message, $attribute, $rule, $parameters) { | |
return str_replace([':attribute', ':values'], [$attribute, implode(',', $parameters)], $message); | |
}); | |
// Usage | |
Rule: extensions:extension1,extension2 | |
In context: 'file' => ['required', 'extensions:extension1,extension2'], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment