mcpField
L
laravel:transactions-and-consistency

laravel:transactions-and-consistency

github.com/jpcaparasDevelopment157165 installsUpdated 17w ago
Repository

About laravel:transactions-and-consistency

A Laravel skill for making multi-step database changes atomic and handling retries safely. It covers transaction boundaries, after-commit work, idempotent jobs, and row locking.

Key features

  1. 01Wrap related writes in transactions
  2. 02Defer events and jobs until commit
  3. 03Design idempotent jobs
  4. 04Coordinate writes with row locks
  5. 05Validate invariants before transactions

Use cases

  1. 01Update records and related items atomically
  2. 02Queue jobs only after a successful commit
  3. 03Prevent duplicate effects when jobs retry

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/jpcaparas/superpowers-laravel --skill laravel:transactions-and-consistency

After installing, type/laravel:transactions-and-consistencyin Claude Code to confirm it loaded.

Details

From the project README

Transactions 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::transaction to wrap write sequences and related side-effects
  • Prefer $afterCommit or dispatchAfterCommit() 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
  • Laravel 13+: upsert() throws InvalidArgumentException on an empty uniqueBy — always pass the real unique columns

Comments

Markdown supported