我正在从我的控制器中添加一个laravel作业到我的队列中
- $this->dispatchFromArray(
- 'ExportCustomeRSSearchJob',[
- 'userId' => $id,'clientId' => $clientId
- ]
- );
我想在实现ExportCustomeRSSearchJob类时将userRepository注入依赖项.请问我该怎么做?
我有这个,但它不起作用
- class ExportCustomeRSSearchJob extends Job implements SelfHandling,ShouldQueue
- {
- use InteractsWithQueue,SerializesModels,DispatchesJobs;
- private $userId;
- private $clientId;
- private $userRepository;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($userId,$clientId,$userRepository)
- {
- $this->userId = $userId;
- $this->clientId = $clientId;
- $this->userRepository = $userRepository;
- }
- }
您在handle方法中注入依赖项:
- class ExportCustomeRSSearchJob extends Job implements SelfHandling,DispatchesJobs;
- private $userId;
- private $clientId;
- public function __construct($userId,$clientId)
- {
- $this->userId = $userId;
- $this->clientId = $clientId;
- }
- public function handle(UserRepository $repository)
- {
- // use $repository here...
- }
- }