eloquent-patterns

eloquent-patterns is a skill for Claude Code from AratKruglik/claude-sdlc. It costs 68 tokens per session (1,775 once invoked), scanned A, original, MIT.

A set of guidelines for using Laravel's Eloquent database layer to retrieve and update records safely and efficiently.

In plain words
What is it for?
Use it when writing or reviewing Eloquent queries, relationships, model scopes, bulk operations, soft deletes, or model events.
Why use it?
It helps avoid common database problems such as making one extra query per record, unsafe raw SQL, and incorrect count updates.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the laravel-plugin plugin — 2 skills, 2 agents shipped together

Good fit Use it when writing or reviewing Eloquent queries, relationships, model scopes, bulk operations, soft deletes, or model events.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/aratkruglik/claude-sdlc/eloquent-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add AratKruglik/claude-sdlc --skill eloquent-patterns
Clone the repo
git clone --depth 1 https://github.com/AratKruglik/claude-sdlc

Made for: Claude Code.

Or install laravel-plugin, the plugin that ships this one along with the rest of its 2 skills, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for eloquent-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/eloquent-patterns/github.svg)](https://agentmods.dev/skills/aratkruglik/claude-sdlc/eloquent-patterns)
Your own site
<a href="https://agentmods.dev/skills/aratkruglik/claude-sdlc/eloquent-patterns"><img src="https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/eloquent-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for eloquent-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/aratkruglik/claude-sdlc/eloquent-patterns"><img src="https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/eloquent-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 68 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,775 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00068 $0.01775
Opus 5 $0.00034 $0.00888
Sonnet 5 $0.00014 $0.00355
Haiku 4.5 $0.00007 $0.00178

Measured 12d ago against content hash d8c06ef864d5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

eloquent-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/laravel-plugin/skills/eloquent-patterns/SKILL.md · 310 lines

How it starts

The opening of the file, as written. The whole thing — 310 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Eloquent Patterns

Patterns for working with Eloquent that catch the common pitfalls (N+1, mass assignment, race conditions on counts, raw SQL injection).

1. N+1 prevention

The single most common Eloquent performance bug.

Problem

$users = User::all();
foreach ($users as $user) {
    echo $user->subscription->plan;  // 1 query per user → N+1
}

Solution: eager loading

$users = User::with('subscription')->get();
foreach ($users as $user) {
    echo $user->subscription?->plan;  // No extra queries
}

Nested eager loading

$users = User::with('subscription.invoices')->get();

Selective columns (further optimization)

$users = User::with(['subscription:id,user_id,plan,status'])->get();

Detection in code review

Look for any foreach or array_map over an Eloquent collection followed by ->relation access without with() upstream. That's N+1 90% of the time.

2. Scopes for reusable query logic

Encapsulate common query fragments as model scopes.

class Subscription extends Model
{
    public function scopeActive(Builder $query): void
    {
        $query->where('status', 'active')
              ->where('ends_at', '>=', now());
    }

    public function scopeForUser(Builder $query, User $user): void
    {
        $query->where('user_id', $user->id);
    }
}

// Usage:
$activeForUser = Subscription::active()->forUser($user)->get();

Benefits:

  • DRY — definition lives once.
  • Testable — scopes can be unit-tested.
  • Self-documenting — Subscription::active() reads better than where('status', 'active')->where(...).

3. Mass assignment safety

class Subscription extends Model
{
    protected $fillable = [
        'user_id',
        'plan',
        'status',
        'starts_at',
    ];
}

Then:

Subscription::create($request->validated());  // ✅ safe

Never:

class Subscription extends Model
{
    protected $guarded = [];  // ❌ — opens door to mass-assigning is_admin, etc.
}

Read the full file on GitHub · 310 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 310 lines · 68 tokens per session scan A d8c06ef864d5

Subscribe to this mod's changes

eloquent-patterns is a skill published in the GitHub repository AratKruglik/claude-sdlc (33 stars, last pushed 8d ago), licensed MIT. It adds 68 tokens to every session and 1,775 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

truss-schema

Ground a database schema change in this application's real structure using Laravel Truss. Use when adding or altering tables, columns, indexes, or foreign keys, when a migration needs to match what is already there, or when you need to know what a migration actually changed. Structure only, never data.

albertoarena/laravel-truss · 63 tokens

laravel-database-optimization

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

AsyrafHussin/agent-skills · 55 tokens

check-batch-processing

Analyzes PHP code for batch processing issues. Detects single-item vs bulk operations, missing batch inserts, individual API calls in loops, transaction overhead.

dykyi-roman/awesome-claude-code · 35 tokens

laravel-migrations

Use when designing a database schema or managing Laravel 13 migrations — Schema Builder, columns, indexes, foreign keys, or seeders.

fusengine/agents · 32 tokens

laravel-eloquent

Eloquent and query-layer engineering rules for Laravel — eliminating N+1, choosing a pagination strategy, short atomic transactions, casts and scopes on the model, where raw SQL is allowed, and how migrations declare the schema those queries depend on. Use when writing or reviewing Eloquent models, migrations, query…

Foysal50x/skills · 93 tokens

Laravel Migration Safety Review

Reviews Laravel migrations for destructive operations, change() dropping modifiers, locking index creation on large tables (PostgreSQL), and asymmetric down().

s977043/river-review · 32 tokens