Support the ongoing development of Laravel.io →
Eloquent IOC
Last updated 1 year ago.
0
Solution

aside from the fact that you should not inject your Models you should use

Illuminate\Validation\Factory

instead of the facade

Validator

see http://laravel.com/docs/facades#facade-class-reference

Last updated 1 year ago.
0

zenry said:

aside from the fact that you should not inject your Models you should use

Illuminate\Validation\Factory

instead of the facade

Validator

see http://laravel.com/docs/facades#facade-class-reference

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')
	);
});
Last updated 1 year ago.
0

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!

Last updated 1 year ago.
0

you can also put the validator in Model event Saving

http://laravel.com/docs/eloquent#model-observers

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.