aside from the fact that you should not inject your Models you should use
Illuminate\Validation\Factory
instead of the facade
Validator
zenry said:
aside from the fact that you should not inject your Models you should use
Illuminate\Validation\Factory
instead of the facade
Validator
Thanks!
Can you clarify why I shouldn't inject models? Is there a better way to achieve the same result (automatic validation) without injection?
Edit - just to clarify; the binding is as follows:
App::bind('User', function($app) {
return new \Models\User(
App::make('validator')
);
});
Ah ok - that makes sense. I've removed the overloading and now create an instance of the Validator via the IoC in the Model save method; i.e. just before it's needed - hopefully that won't create issues further down the line.
Thanks!
you can also put the validator in Model event Saving
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community