laravel:transactions-and-consistency

Wrap multi-write Laravel operations in DB::transaction blocks with after-commit events.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2 --skill laravel-transactions-and-consistency-patkik
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel:transactions-and-consistency
Source: https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2/tree/main/.agents/skills/transactions-and-consistency
Command: npx skills add https://github.com/Patkik/Multi-tenant-SaaS-Catering-V2 --skill laravel-transactions-and-consistency-patkik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Multi-step write operations across related data models can become inconsistent if some steps fail. This skill guides wrapping changes in transactions, using after-commit logic and idempotent patterns to maintain data integrity.

Core Features & Use Cases

  • Atomic writes across related models using DB::transaction.
  • After-commit dispatch for events and jobs to prevent premature side-effects.
  • Idempotent operations and row-level locking to guard invariants during retries.
  • Use case: creating an order and its items, then emitting invoices only after the transaction commits.

Quick Start

Ensure all related writes run inside a DB::transaction block and return a consistent state after commit, using dispatchAfterCommit for events.

Frequently Asked Questions about laravel:transactions-and-consistency

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

FAQPage Schema
How do I ensure atomic database transactions across multiple related Laravel models?

To ensure atomic database transactions across related Laravel models, wrap multi-step write operations inside a DB::transaction block. This guarantees that all changes commit together or roll back entirely, maintaining data consistency if any step fails.

Why do my Laravel queued jobs dispatch before the database transaction commits?

Laravel queued jobs dispatch prematurely because they are not configured with after-commit logic. Using dispatchAfterCommit for events and jobs prevents premature side-effects by ensuring they only execute after the database transaction successfully commits.

How do I handle idempotency and row locking during Laravel transaction retries?

Handle idempotency and row locking during Laravel transaction retries by applying idempotent operations and row-level locking within the transaction. These guardrails protect data invariants and prevent duplicate side-effects when concurrent processes or failed operations occur.

What is the best way to create an order and emit invoices only after commit in Laravel?

The best way to create an order and emit invoices after commit in Laravel is wrapping the order and item creation in a DB::transaction block, then using after-commit dispatch for the invoice generation to prevent premature side-effects.

When do I need database transactions and after-commit events in Laravel?

You need database transactions and after-commit events in Laravel when performing related writes across multiple data models. This mechanism ensures transactional boundaries are respected and data integrity is maintained if partial step failures occur.