Try the following:
- Make a bind class where you can implement each rule you want extending
Validator
class.
- Make a service provider that extends
ServiceProvider
.
- Add your custom validator provider at
config/app.php
file.
You can create the bind at Services
folder like this:
namespace MyAppServices;
class Validator extends IlluminateValidationValidator{
public function validateFoo($attribute, $value, $parameters){
return $value == "foo"
}
}
Then, use a service provider to extends the core:
namespace MyAppProviders;
use MyAppServicesValidator;
use IlluminateSupportServiceProvider;
class ValidatorServiceProvider extends ServiceProvider{
public function boot()
{
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new Validator($translator, $data, $rules, $messages);
});
}
public function register()
{
}
}
Finally, import your service provider at config/app.php
like so:
'providers' => [
...
...
'MyAppProvidersValidatorServiceProvider';
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…