An underrated Laravel feature I use all the time in my Action classes: Simple, clean, and saves you from some nasty race conditions. That's why I love using @laravel !
afterCommit().
If you're dispatching jobs inside database transactions, this little gem ensures they’re only dispatched after the transaction successfully commits.
app/Actions/CompleteOrderAction.php
DB::transaction(function () use ($order) { $order->update(['status' => 'paid']); SendOrderConfirmation::dispatch($order)->afterCommit(); });
commit 4b2c117