2015-10-31 10 views
6

मैं ऐसेकैसे एक laravel काम

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

के रूप में मेरी नियंत्रक से मेरी कतार में एक laravel काम जोड़ रहा करने के लिए निर्भरता सुई मैं जब 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; 
    } 
} 

उत्तर

7

आप handle विधि में अपनी निर्भरता इंजेक्षन:

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