Field Manual PHP / Laravel reference
← Engineering

Transactions

A transaction boundary defines which database changes succeed together.

What it is

A transaction boundary defines which database changes succeed together.

When to use it

Use for a cohesive multi-write business operation.

Syntax

DB::transaction(fn () => $operation->apply());

Example

// Keep short:
// Validate/authorize before expensive work.
// Inside transaction: read protected state, enforce invariants, write, audit.
// After commit: schedule external effects safely.

Common mistakes

A transaction cannot roll back an email or provider charge; closure retries may repeat side effects.

Related topics

TransactionsTransactionsDatabase transactions