Support the ongoing development of →
posted 10 years ago
Last updated 2 years ago.

You dont have to have to do that. Just inject the right class in the constructor. In my opinion theres no need to try and abstract any more away, than what you have already done.

use PathToClass\LoginValidator;

class LoginService {

  protected $validator;

  function __construct(LoginValidator $validator){
    $this->validator = $validator;

Last updated 2 years ago.

Thanks @Herlevsen

That's what I'm doing now.

I'm pretty new to OOP and I'd like to stick to the best practice all the time.

Saw some laravel videos doing this for subclass so I think I should do this too and then stuck at this...

Last updated 2 years ago.

Why wouldn't this be best practice? Your Login Service will ALWAYS be validated by the LoginValidator. Even if you some time want to switch to a more advanced (Login)Validator, you can still extend LoginValidator, so that the injection still works.

It doesn't make sense to use an abstract validator, when you know which one it will be.

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

wppd wppd Joined 12 Feb 2014


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.

© 2024 - All rights reserved.