2015-10-31 19 views
6

Böylebir laravel işi

$this->dispatchFromArray(
    'ExportCustomersSearchJob', 
    [ 
     'userId' => $id, 
     'clientId' => $clientId 
    ] 
); 

olarak benim denetleyicisi benim kuyruğuna bir laravel işi ekliyorum için bağımlılıkları enjekte etmek nasıl ExportCustomersSearchJob sınıf uygularken bir bağımlılık olarak userRepository enjekte etmek istiyorum. Lütfen bunu nasıl yapabilirim?

Bunu alabilir ama sen handle stilini bağımlılıkları enjekte

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; 
    } 
} 

cevap

7

çalışmaz:

class ExportCustomersSearchJob extends Job implements SelfHandling, ShouldQueue 
{ 
    use InteractsWithQueue, SerializesModels, DispatchesJobs; 

    private $userId; 

    private $clientId; 

    public function __construct($userId, $clientId) 
    { 
     $this->userId = $userId; 
     $this->clientId = $clientId; 
    } 

    public function handle(UserRepository $repository) 
    { 
     // use $repository here... 
    } 
}