Created
February 13, 2015 09:26
-
-
Save luceos/cb4e8655d64c3fe7657e to your computer and use it in GitHub Desktop.
extending laravel 4 validation
This file contains hidden or 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 Vendor\Package; | |
use Illuminate\Validation\Validator; | |
class ExtendedValidator extends Validator | |
{ | |
// use validation rule "foo" to use | |
public function validateFoo($attribute, $value, $parameters) | |
{ | |
return $value == "foo"; | |
} | |
// add more validation rules | |
} | |
/** | |
* In your service provider, registered in app/config/app.php add | |
* @info please note this is a different php file! | |
*/ | |
//.. opening php tag and namespace definition see above | |
use Illuminate\Support\ServiceProvider; | |
class PackageServiceProvider extends ServiceProvider | |
{ | |
public function register() | |
{ | |
Validator::resolver(function($translator, $data, $rules, $messages) | |
{ | |
return new ExtendedValidator($translator, $data, $rules, $messages); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment