Question: In Laravel 5.3, how to get the Job ID after we dispatch a job to the job queue?

Question

In Laravel 5.3, how to get the Job ID after we dispatch a job to the job queue?

Answers 1
Added at 2016-12-27 15:12
Tags
Question

In Laravel 5.3, in the controller, we can dispatch a job to the job queue like this:

$job = (new JobClass())->onQueue('queuename');
dispatch($job);

In the Job class which is using InteractsWithQueue trait, in the handle function, we can get the Job ID like this:

$this->job->getJobId();

But, I would like to get the Job ID in my controller after I use the dispatch($job).

How to get the Job ID in controller?

If there is no such function available, can we extend the dispatch helper function to add this function?

Answers
nr: #1 dodano: 2016-12-28 00:12

The dispatch() function will return the Job id:

$job = (new JobClass())->onQueue('queuename');
$jobId = dispatch($job);

dd($jobId);
Source Show
◀ Wstecz