0091-laravel-transactions-and-consistency

Wrap Laravel multi-step writes in DB::transaction with after-commit dispatch.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/MrJmpl3/codex_____data_____configuration --skill 0091-laravel-transactions-and-consistency
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: 0091-laravel-transactions-and-consistency
Source: https://github.com/MrJmpl3/codex_____data_____configuration/tree/main/skills/0091-laravel-transactions-and-consistency
Command: npx skills add https://github.com/MrJmpl3/codex_____data_____configuration --skill 0091-laravel-transactions-and-consistency

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents inconsistent database state when multiple related writes and side-effects must succeed or fail together, especially under concurrency and retries.

Core Features & Use Cases

  • Atomic multi-write updates: Use DB::transaction to wrap related model updates and bulk creates as a single unit of work.
  • After-commit side-effects: Dispatch events/jobs only after the transaction commits (e.g., using dispatchAfterCommit or setting $afterCommit = true) to avoid acting on rolled-back data.
  • Idempotent retry safety: Make queued jobs and event handlers safe to run multiple times using state checks and unique constraints.
  • Concurrency coordination: Use lockForUpdate when multiple workers must coordinate on the same rows.

Example: Updating an order and inserting its items should never leave an order saved without its items, and invoice sending should only happen once the transaction is permanently committed.

Quick Start

Use the 0091-laravel-transactions-and-consistency skill to refactor your Laravel workflow so order updates, item creation, and follow-up events run atomically with after-commit dispatch and idempotent retry-safe jobs.

Frequently Asked Questions about 0091-laravel-transactions-and-consistency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent partial database writes in Laravel when updating an order and inserting its items?▼

Wrap related model updates and bulk creates in Laravel using DB::transaction to ensure atomic multi-write consistency, so all changes succeed or fail together without leaving partial records.

Why are my Laravel queued jobs processing data that was rolled back during a database transaction?▼

Queued jobs dispatched inside transactions may act on rolled-back data. Use dispatchAfterCommit or set $afterCommit = true to dispatch events and jobs only after the transaction permanently commits.

What is the best way to make Laravel queued jobs safe to retry without duplicating side-effects?▼

Make Laravel queued jobs idempotent by implementing state checks and unique constraints, ensuring event handlers and side-effects like invoice sending run safely multiple times without duplication.

How do I handle concurrency control in Laravel when multiple workers update the same database rows?▼

Use Laravel's lockForUpdate within database transactions to coordinate concurrent workers, preventing race conditions when multiple processes must update or read the same rows simultaneously.

When do I need idempotency and row locking in Laravel transactional workflows?▼

You need idempotency and row locking in Laravel when multi-step writes face concurrency and retries, ensuring atomic consistency, preventing duplicate side-effects, and coordinating simultaneous worker access.