I am trying to utilize a service provider from a custom package:
class ReferralsServiceProvider extends ServiceProvider
{
public const PACKAGE_NAME = 'referrals';
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
...
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->bind(PreReferralsRepositoryInterface::class, WorkflowPreReferrals::class);
}
The service provider is registered in the packages composer.json file so it’s auto-registered in the utilizing application.
"extra": {
"laravel": {
"providers": [
"PropelReferralsReferralsServiceProvider"
]
}
}
However in one of the controllers we have in main application:
class ReferalValidationController extends Controller
{
protected $referrals;
public function __construct(PreReferralsRepositoryInterface $referrals)
{
...
}
I get the error:
Argument 1 passed to AppHttpControllersReferalValidationController::__construct() must be an instance of PropelReferralsRepositoriesPreReferralsRepositoryInterface, instance of PropelReferralsRepositoriesWorkflowPreReferrals given
I know for a fact the service provider is registered as I can change the second parameter of the binding to another class and it will then reflect in the error. Have I missed out something critical in the binding? Its almost as if the controller is unaware of the service provider.
Source: Laravel