Chains & Batches
Executables plug into Laravel's chains and batches through prepare() mode. It returns a real Laravel job object that you can use anywhere a job is expected. Everything else on this page (Bus::chain(), Bus::batch(), ->name(), ->allowFailures(), callbacks) is standard Laravel.
Chains
php
ProcessOrder::onQueue()
->chain([
SendConfirmation::prepare()->execute($order),
UpdateInventory::prepare()->execute($order),
NotifyWarehouse::prepare()->execute($order),
])
->execute($order);Chain-wide settings:
php
ProcessOrder::onQueue()
->allOnConnection("redis")
->allOnQueue("orders")
->chain([SendConfirmation::prepare()->execute($order), UpdateInventory::prepare()->execute($order)])
->execute($order);You can also use Bus::chain() directly with prepared executables:
php
Bus::chain([
ProcessOrder::prepare()->execute($order),
SendConfirmation::prepare()->execute($order),
UpdateInventory::prepare()->execute($order),
])->dispatch();Batches
php
Bus::batch([
ProcessOrder::prepare()->execute($orderA),
ProcessOrder::prepare()->execute($orderB),
ProcessOrder::prepare()->execute($orderC),
])
->name("process-daily-orders")
->onQueue("orders")
->allowFailures()
->then(fn(Batch $batch) => Log::info("All done"))
->catch(fn(Batch $batch, Throwable $e) => Log::error($e->getMessage()))
->dispatch();