I’m using Laravel 7. would like like to inject services into a event listener. Injecting their interfaces through the constructor works fine, but when I add “implements ShouldQueue” to the class so it runs as a job, it sometimes works, but I mainly get ” Target [AppServicesINotificationService] is not instantiable while building [AppListenersNewOpportunityMessage].
https://laravel.com/docs/7.x/container#resolving says “Additionally, you may type-hint dependencies in the handle method of queued jobs”. However if I do this I get a “Too few arguments to function” exception.
https://laravel.com/docs/7.x/events#defining-listeners says “Your event listeners may also type-hint any dependencies they need on their constructors. All event listeners are resolved via the Laravel service container, so dependencies will be injected automatically”.
Please advise on the correct way to inject into a queued listener?
Richard House is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.