我正在这样从控制器向队列添加laravel作业
$this->dispatchFromArray(
'ExportCustomersSearchJob',
[
'userId' => $id,
'clientId' => $clientId
]
);
我想在实现userRepository
类时注入ExportCustomersSearchJob
作为依赖项。请问我该怎么做?
我有这个,但是不起作用
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
方法中:
[如果有人想知道如何将依赖项注入handle
函数: