db); $batch_key = Str::uuid(); $invites = $this->class::with('invitations')->withTrashed() ->whereIn('id', $this->entity_ids) ->get() ->map(function ($entity) use ($batch_key) { return new CreateBatchablePdf($entity->invitations->first(), "{$batch_key}-{$entity->id}"); })->toArray(); $mergedPdf = null; $batch = Bus::batch($invites) ->before(function (Batch $batch) { // The batch has been created but no jobs have been added... // nlog("before"); })->progress(function (Batch $batch) { // A single job has completed successfully... // nlog("Batch {$batch->id} is {$batch->progress()}% complete"); })->then(function (Batch $batch) { // All jobs completed successfully... // nlog("job finished"); })->catch(function (Batch $batch, Throwable $e) { // First batch job failure detected... nlog("PrintEntityBatch failed: {$e->getMessage()}"); })->finally(function (Batch $batch) { // The batch has finished executing... // nlog("I have finished"); })->name($batch_key)->dispatch(); return $batch->id; } }