L
laravel-transactions-and-consistency
About laravel-transactions-and-consistency
A Laravel skill for keeping multi-step database writes consistent. It covers transaction boundaries, after-commit events and jobs, idempotent retries, and row-level locking.
Key features
- 01Wrap related writes in transactions
- 02Dispatch events and jobs after commit
- 03Make jobs safe to retry
- 04Coordinate writes with row locks
- 05Validate invariants before transactions
Use cases
- 01Update an order and its items atomically
- 02Delay invoice jobs until commit
- 03Prevent duplicate effects when retrying jobs
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ noartem/ skills --skill laravel-transactions-and-consistencyAfter installing, type/laravel-transactions-and-consistencyin Claude Code to confirm it loaded.
Details
From the project READMETransactions and Consistency
Ensure multi-step changes are atomic; make retries safe.
Commands
DB::transaction(function () use ($order, $payload) {
$order->update([...]);
$order->items()->createMany($payload['items']);
OrderUpdated::dispatch($order); // or flag for after-commit
});
// Listener queued after commit
class SendInvoice implements ShouldQueue {
public $afterCommit = true;
}
Patterns
- Use
DB::transactionto wrap write sequences and related side-effects - Prefer
$afterCommitordispatchAfterCommit()for events / jobs - Make jobs idempotent (check existing state, use unique constraints)
- Use
lockForUpdate()for row-level coordination when needed - Validate invariants at the boundary before starting the transaction
Comments
Markdown supported