Last active
January 3, 2017 13:45
-
-
Save vluzrmos/4de2cb5a1fcb22b2a60a to your computer and use it in GitHub Desktop.
Laravel - Simple file extension validator
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 | |
namespace App\Providers; | |
use Illuminate\Support\ServiceProvider; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
class ValidatorServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
* | |
* @return void | |
*/ | |
public function boot() { | |
$this->app['validator']->extend('ext', function ($attribute, $value, $params) { | |
if (!($value instanceof UploadedFile && $value->isValid())) { | |
return false; | |
} | |
$ext = $value->getClientOriginalExtension(); | |
return in_array($ext, $params); | |
}); | |
} | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage