1

The title would be vague due to my English. Hope someone can improve it.

Here is the thing:

I have one abstract class Validator.

Currently, I have two subclasses, LoginValidator and SignupValidator , which extend from Validator.

I have two services: LoginService and SignupService and they have the same function __construct(Validator $validator)

I wrote two ServiceProviders to bind the Validator.

LoginServiceProvider.php

$this->app->bind('Validators\Validator','Validators\LoginValidator');

SignupServiceProvider.php

$this->app->bind('Validators\Validator','Validators\SignupValidator');

Therefore, the $validator in __construct(Validator $validator) is actually always resolved to SignupValidator. I know the reason.

I wonder if there is any way to make sure that:

class LoginService {
  //$validator will be LoginValidator
  function __construct(Validator $validator){}

}

class SignupService {
  //$validator will be SignupValidator
  function __construct(Validator $validator){}
}

OR

I'm simply wrong, I should do __construct(LoginValidator $validator) ?

Jesse
  • 231
  • 7
  • 17

1 Answers1

0

The question was answered by someone here at Laravel.io I found it useful so I am posting the link here -Thanks

masoodahm
  • 195
  • 1
  • 10