Support the ongoing development of Laravel.io →
Eloquent IOC
Last updated 2 weeks ago.
0

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 2 weeks 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 2 weeks 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 2 weeks ago.
0

you can also put the validator in Model event Saving

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

Last updated 2 weeks ago.
0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.