Laravel Eloquent N+1 and Query Efficiency Review

Laravel Eloquent N+1 and Query Efficiency Review is a skill for Claude Code from s977043/river-review. It costs 48 tokens per session (1,010 once invoked), scanned A, original, MIT.

A Laravel code review check for inefficient Eloquent database queries, including repeated relation queries inside loops and loading entire tables at once.

In plain words
What is it for?
It reviews changed Laravel model-query code for missing eager loading, unsafe full-table reads, and incorrect use of chunking or cursors.
Why use it?
It helps prevent slow code and excess database work caused by fetching the same related data repeatedly or processing too many records in memory.

Skill for Claude Code

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

Part of the river-review plugin — 138 skills, 18 commands, 5 agents, 3 hooks shipped together

Good fit It reviews changed Laravel model-query code for missing eager loading, unsafe full-table reads, and incorrect use of chunking or cursors.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/s977043/river-review/laravel-eloquent-nplus1
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 s977043/river-review --skill laravel-eloquent-nplus1
Clone the repo
git clone --depth 1 https://github.com/s977043/river-review

Made for: Claude Code.

Or install river-review, the plugin that ships this one along with the rest of its 138 skills, 18 commands, 5 agents, 3 hooks.

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 Laravel Eloquent N+1 and Query Efficiency Review

README.md
[![agentmods](https://agentmods.dev/badge/skills/s977043/river-review/laravel-eloquent-nplus1/github.svg)](https://agentmods.dev/skills/s977043/river-review/laravel-eloquent-nplus1)
Your own site
<a href="https://agentmods.dev/skills/s977043/river-review/laravel-eloquent-nplus1"><img src="https://agentmods.dev/badge/skills/s977043/river-review/laravel-eloquent-nplus1/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 Laravel Eloquent N+1 and Query Efficiency Review

Your own site · 80×15
<a href="https://agentmods.dev/skills/s977043/river-review/laravel-eloquent-nplus1"><img src="https://agentmods.dev/badge/skills/s977043/river-review/laravel-eloquent-nplus1.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 48 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,010 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.
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.00048 $0.01010
Opus 5 $0.00024 $0.00505
Sonnet 5 $0.00010 $0.00202
Haiku 4.5 $0.00005 $0.00101

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

Security

Grade A, and why

Laravel Eloquent N+1 and Query Efficiency Review 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 8d 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.

skills/midstream/laravel-eloquent-nplus1/SKILL.md · 76 lines

What it actually says

Pattern declaration

Primary pattern: Reviewer Secondary patterns: Inversion Why: Eloquent のクエリ効率規約への適合をチェックリスト型で検査する

Goal / 目的

  • ループ内 relation アクセスによる N+1 クエリ(公式例: 25 件で 26 クエリ)を検出する。
  • 巨大テーブルの全件ロード(all() / get())と、chunk() / cursor() の誤用を検出する。

Non-goals / 扱わないこと

  • mass assignment / 認可(laravel-mass-assignment のスコープ)。
  • migration の安全性(laravel-migration-safety のスコープ)。
  • SQL チューニング一般・index 設計。

Pre-execution Gate / 実行前ゲート

このスキルは以下の条件がすべて満たされない限りNO_REVIEWを返す。

  • 差分に Eloquent モデルのクエリ・relation アクセスの追加変更が含まれている
  • diff コンテキストが利用可能である

ゲート不成立時の出力: NO_REVIEW: laravel-eloquent-nplus1 — Eloquent クエリの変更なし

False-positive guards / 抑制条件

  • ループ前に with() / load() 済みの relation へのアクセスは指摘しない(diff 外で eager load されている可能性があるため、確証がなければ質問に留める)。
  • ループ対象が少数固定(config 由来等)の場合の relation アクセスは指摘しない。
  • chaperone() を使った親逆参照は正当。
  • preventLazyLoading が有効なプロジェクトでは N+1 がテストで落ちるため、重複指摘を避ける。

Rule / ルール

  • ループ内で relation を参照する場合は with('relation')(取得後なら load() / loadCount())で eager load する。
  • 巨大テーブルの反復は chunkById / lazyById / cursor を使う。
  • chunk() でフィルタ対象カラムを更新しない(公式: inconsistent results。chunkById を使う)。
  • cursor() と eager loading を併用しない(cursor は relation を eager load できない。lazy を使う)。
  • chunkById / lazyByIdorWhere を含む条件は closure で論理グループ化する。

Evidence / 根拠の取り方

  • 指摘は <file>:<line> で差分に紐づけ、公式規約(laravel.com/docs/12.x/eloquent-relationships#eager-loading 等)を 1 行で添える。
  • eager load の有無が diff から確定できない場合は断定せず questions で返す。

Output / 出力(短文版の推奨)

コメントは日本語で返す。

  • Finding: N+1 / 全件ロード / chunk 誤用のどれか(1文)
  • Impact: クエリ数 / メモリ / 一貫性への影響
  • Fix: with() / chunkById / lazy 等の最小修正案

Sources / 出典

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 8d ago First seen · 76 lines · 48 tokens per session scan A 715033b73c9c

Subscribe to this mod's changes

Laravel Eloquent N+1 and Query Efficiency Review is a skill published in the GitHub repository s977043/river-review (3 stars, last pushed yesterday), licensed MIT. It adds 48 tokens to every session and 1,010 once invoked, about $0.0002 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-09-03.

Related

Other skills, from other repositories

laravel

Use when building or extending a Laravel 11/12 app — Eloquent models, migrations and relationships, routing with controllers and Form Requests, queues and background jobs, framework-native security (validation, mass-assignment, policies, signed URLs, rate limiting), and Pest/PHPUnit feature tests. NOT pure PHP…

ericrisco/rsc-harness · 76 tokens

php-laravel

Modern PHP 8.2+ and Laravel patterns: architecture, Eloquent, queues, Pest testing. Use when asked to "write PHP", "build a Laravel app", "fix Eloquent query", "add a queue job", "write a Pest test", or mentions PHP, Laravel, Eloquent, Blade, artisan, or migrations.

iliaal/whetstone · 74 tokens

ia-php-laravel

Modern PHP 8.4 and Laravel patterns: architecture, Eloquent, migrations, queues, testing. Use when working with Laravel, Eloquent, Blade, artisan, or building/testing a framework-based PHP app. Not for php-src internals, standalone PHP libraries, or general PHP language discussion.

iliaal/whetstone · 67 tokens

performance-audit

Full-stack performance health check across 12 dimensions. Rendering, bundles, assets, API/network, algorithms, memory, database, caching, Web Vitals, backend runtime, concurrency, and framework-specific pathologies. Evidence-based Impact Models with confidence tiers and a prioritized optimization roadmap. Switches…

greglas75/zuvo · 90 tokens

craft-provider

Crafting a service provider. The declarative heart of every Laravel package.

attac-t/the-foundry · 18 tokens

craft-middleware

Crafting package middleware. The invisible gatekeepers that guard, transform, and decorate every request.

attac-t/the-foundry · 23 tokens