Reputation: 8151
I wanted extend the Validator class in Laravel. However in all examples the make method is used to create a new instance which I can't find in the Validator source code. How can I override this method? The constructor requires a TranslatorInterface
instance so that doesn't seem to be an option?
Upvotes: 2
Views: 776
Reputation: 18665
The make
method is actually in Illuminate\Validation\Factory
.
If you want to extend this method then you'll need to swap out the IoC binding. Just overload the binding in the container.
App::bindShared('validator', function($app)
{
$validator = new \Your\Validator\Factory($app['translator'], $app);
if (isset($app['validation.presence']))
{
$validator->setPresenceVerifier($app['validation.presence']);
}
return $validator;
});
Upvotes: 3