/syarif-laravel-ai-skills:database-transactionsfrom syarif-laravel-ai-skills
Keeps Laravel writes atomic and consistent using transactions, row locks, retries, idempotency keys, side-effect boundaries, and after-commit dispatch patterns.
Ships in syarif-laravel-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use database transactions for write operations that must be atomic.
This is the canonical transaction skill. It consolidates the former transactions-and-consistency topic.
Transaction boundaries usually belong inside an Action or Service, not spread across controllers.
Use DB::transaction() when a workflow:
final class CreateRecord
{
public function handle(User $actor, array $data): Record
{
return DB::transaction(function () use ($actor, $data) {
$record = Record::create([
'owner_id' => $actor->id,
'name' => $data['name'],
]);
$record->items()->createMany($data['items'] ?? []);
return $record->fresh(['items']);
});
}
}
Database rollbacks do not roll back files. Track stored paths and clean them up when the database write fails.
$storedPaths = [];
try {
DB::transaction(function () use ($request, &$storedPaths) {
$record = Record::create([...]);
foreach ($request->file('attachments', []) as $file) {
$storedPaths[] = $file->store("records/{$record->id}", 'public');
}
});
} catch (Throwable $exception) {
Storage::disk('public')->delete($storedPaths);
throw $exception;
}
For delete flows, prefer committing database/audit changes first, then deleting files after the successful transaction unless the product explicitly requires the opposite failure mode.
Use row locks for concurrent updates to shared counters, balances, or ordered state.
DB::transaction(function () use ($recordId) {
$record = Record::query()
->whereKey($recordId)
->lockForUpdate()
->firstOrFail();
$record->increment('sequence');
});
Keep transactions short. Make retry behavior idempotent when deadlock retries are used.
Dispatch queued jobs/events after commit when they depend on committed records.
Do not hold a database transaction open during slow HTTP calls, mail delivery, document generation, or other remote side effects. Persist the state needed to continue, commit it, and dispatch after commit. Use an outbox or equivalent durable handoff when losing the side effect would be unacceptable.
Test:
Layer: 3 (Implementation)
Load this skill only when writes need atomicity or consistency. Do not load with unrelated skills. Keep transactions short, idempotent, and after-commit for side effects. No open transaction during slow HTTP calls or mail delivery.
What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (soden46/syarif-laravel-ai-skills) — no native marketplace selected
npx claudepluginhub p/soden46-syarif-laravel-ai-skills72 skills in this plugin
/actions-and-servicesUse Actions and Services as deliberate Laravel application boundaries for use cases, integrations, and reusable workflows./ai-sdkBuild AI features with the first-party Laravel AI SDK (Laravel 13+); agents, embeddings, images, audio, and tool calling with provider-agnostic APIs/api-resources-and-paginationLaravel guidance to use API Resources with pagination and conditional fields; keep response shapes stable and cache-friendly