Jobs don't typically dispatch other Jobs, so start by removing the DispatchJobs
trait. What you can do is listen for job events.
When a Job completes, it fires the after
event. Listen for this event and then dispatch()
the next Job within the listener:
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Queue::after(function (JobProcessed $event) {
// determine the job type from $event->job
// then dispatch the next job based on your logic
// check the job type
if ($event->job instanceof MyJob) {
// get the job payload to pass to next job
$data = $event->job->payload
dispatch(new NextJob($data));
// or use the static method
NextJob::dispatch($data);
}
});
}