/laravel-skill:laravel-eloquentfrom laravel-skill
45 rules for Eloquent query-layer engineering: eliminating N+1, pagination strategy, atomic transactions, model casts/scopes, raw SQL policy, and migration schema design. Apply when writing or reviewing models, queries, repositories, or debugging slow/memory-heavy endpoints.
Ships in laravel-skill. 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.
Read when SKILL.md points to them.
Data-layer engineering rules: 45 rules across 8 sections, ordered by what actually takes an application down.
Assumes the layering from the laravel-patterns skill: all query construction lives in Query Classes and Repository implementations. These rules describe what goes inside those classes.
| About to write | Read |
|---|---|
| A query that reads relations | perf-eager-load-every-touched-relation, perf-prevent-lazy-loading |
| A query returning many rows | paginate-always-paginate-lists, paginate-cursor-for-deep-pagination |
| A new model | model-cast-every-column, model-final-and-typed, model-minimal-fillable |
| A write touching more than one table | tx-wrap-multi-step-writes, tx-keep-transactions-short |
| Raw SQL or a database expression | raw-never-interpolate-user-input, raw-only-inside-query-classes |
| An update or insert over many rows | bulk-update-bypasses-events, bulk-upsert-instead-of-loop |
| A filter used by several queries | scope-query-scopes-for-reusable-filters |
| An existence check | perf-exists-not-count |
| A pass over a large table | perf-chunk-large-result-sets, bulk-lazy-by-id-for-huge-sets |
| A slow endpoint to diagnose | perf-index-filtered-columns, perf-avoid-wherehas-on-hot-paths |
| One value from a has-many | perf-subquery-select-for-single-values |
| Sorting by a related table's column | perf-order-by-correlated-subquery |
| A count of related rows | perf-withcount-not-loaded-relations |
| A migration | migration-never-edit-a-deployed-migration, migration-constrained-foreign-keys |
| A backfill or default value | migration-separate-schema-from-data, migration-mirror-defaults-in-the-model |
^12.0 || ^13.0 and PHP ^8.3. If you need something these rules do not name, check the docs — never infer an API from its name.composer.json first; on Laravel 12 use the fallback the rule gives.rules/{slug}.md before adapting it to a case the example does not show.| # | Section | Impact | Prefix |
|---|---|---|---|
| 1 | Query Performance | CRITICAL | perf- |
| 2 | Pagination | HIGH | paginate- |
| 3 | Transactions and Consistency | HIGH | tx- |
| 4 | Model Declaration | HIGH | model- |
| 5 | Scopes, Global Scopes and Soft Deletes | MEDIUM-HIGH | scope- |
| 6 | Migrations and Schema | MEDIUM-HIGH | migration- |
| 7 | Raw SQL and Query Expressions | MEDIUM | raw- |
| 8 | Bulk Operations | MEDIUM | bulk- |
perf-eager-load-every-touched-relation — Every relation the output touches is in with([...])perf-prevent-lazy-loading — Make lazy loading throw outside productionperf-select-only-needed-columns — Narrow the select on wide tablesperf-exists-not-count — Ask exists() when you only need a booleanperf-chunk-large-result-sets — Chunk or stream instead of get()perf-avoid-wherehas-on-hot-paths — Replace whereHas with a join on hot pathsperf-index-filtered-columns — Index every column you filter, join or sort onperf-withcount-not-loaded-relations — Count with withCount(), never a loaded collectionperf-subquery-select-for-single-values — Pull a single related value with a subqueryperf-order-by-correlated-subquery — Sort by a related value with a subquery, not a joinperf-set-relation-to-close-the-loop — Hand the parent back with setRelation()paginate-always-paginate-lists — Never return an unbounded listpaginate-cursor-for-deep-pagination — cursorPaginate() for deep or fast-growing setspaginate-simple-when-no-total — simplePaginate() when the total is not renderedpaginate-full-only-when-count-required — Reserve paginate() for a required counttx-wrap-multi-step-writes — Multi-step writes are atomictx-keep-transactions-short — No HTTP, mail or file I/O inside a transactiontx-dispatch-after-commit — Jobs and events fire after committx-lock-for-update-on-contention — Lock rows you read then modifytx-retry-on-deadlock — Pass attempts: so deadlocks retrymodel-cast-every-column — Cast every date, enum, JSON and money columnmodel-custom-casts-for-value-objects — Value Objects get a CastsAttributes classmodel-minimal-fillable — $fillable is a security boundarymodel-scope-attribute — Declare scopes with #[Scope] (Laravel 12+)model-observed-by-attribute — Attach observers with #[ObservedBy]model-immutable-dates-and-timezones — Store UTC, cast immutable, convert at the edgemodel-final-and-typed — final, strict_types, typed relations, @property docblocksscope-query-scopes-for-reusable-filters — Small reusable constraints live on the modelscope-global-scope-for-default-filter — Global scope for a filter that must never be forgottenscope-global-or-named-not-both — One filter, one mechanismscope-soft-deletes-for-recoverable — SoftDeletes only for genuinely recoverable recordsscope-explicit-trashed-queries — Name the query after what it includesmigration-never-edit-a-deployed-migration — Once it has run in production it is historymigration-separate-schema-from-data — Structure in one migration, data in anothermigration-constrained-foreign-keys — constrained() plus an explicit delete behaviourmigration-reversible-down — Write a down() that actually reverses up()migration-mirror-defaults-in-the-model — The same default in $attributesraw-only-inside-query-classes — Raw SQL belongs in Query Classes and Repositoriesraw-tpetry-instead-of-db-raw — Type-safe expressions instead of DB::raw()raw-conditional-aggregates-in-one-query — Dashboard counters in a single queryraw-custom-expression-helpers — Wrap driver-specific SQL in an Expression classraw-never-interpolate-user-input — Bindings for values, allow-lists for identifiersbulk-upsert-instead-of-loop — Batch inserts and upsertsbulk-update-bypasses-events — Bulk writes skip model events; handle that deliberatelybulk-lazy-by-id-for-huge-sets — chunkById/lazyById, never offset paging while writingVerified against Laravel 13:
| Need | Package | Constraint |
|---|---|---|
Type-safe SQL expressions (replaces DB::raw()) | tpetry/laravel-query-expressions | ^1.6 |
| Declarative, reusable model filters | indexzer0/eloquent-filtering | ^2.2.2 |
| Excel import and export | rap2hpoutre/fast-excel | ^5.14 |
All three are used inside Query Classes and Repositories only. Drop to raw expressions when a declarative filter package hurts performance on a hot query.
references/n-plus-one-playbook.md — finding, fixing and preventing N+1references/pagination-decision.md — choosing between the three paginatorsreferences/checklist.md — pre-merge self-check for the data layerLoad in this order and stop when the answer is clear:
rules/perf-eager-load-every-touched-relation.md
rules/tx-dispatch-after-commit.md
references/ file only when a rule points at one.AGENTS.md is every rule compiled into one document (~12k tokens), for agents that read the AGENTS.md convention. Do not load it when the individual rule files are reachable.
laravel-engineering — trace the full change and read back through the consumer shapelaravel-patterns — where the query goes: Query Class, Repository, Action or inlinelaravel-rest-api — pagination and resources at the HTTP edgelaravel-async — caching query results and invalidating on model eventslaravel-testing — testing query rules against a real databaseAGENTS.md (opens in a new tab)README.md (opens in a new tab)metadata.json (opens in a new tab)references/checklist.md (opens in a new tab)references/n-plus-one-playbook.md (opens in a new tab)references/pagination-decision.md (opens in a new tab)rules/_sections.md (opens in a new tab)rules/_template.md (opens in a new tab)rules/bulk-lazy-by-id-for-huge-sets.md (opens in a new tab)rules/bulk-update-bypasses-events.md (opens in a new tab)rules/bulk-upsert-instead-of-loop.md (opens in a new tab)rules/migration-constrained-foreign-keys.md (opens in a new tab)rules/migration-mirror-defaults-in-the-model.md (opens in a new tab)rules/migration-never-edit-a-deployed-migration.md (opens in a new tab)rules/migration-reversible-down.md (opens in a new tab)rules/migration-separate-schema-from-data.md (opens in a new tab)rules/model-cast-every-column.md (opens in a new tab)rules/model-custom-casts-for-value-objects.md (opens in a new tab)rules/model-final-and-typed.md (opens in a new tab)rules/model-immutable-dates-and-timezones.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub foysal50x/skills --plugin laravel-skill6 skills in this plugin
/laravel-asyncAsynchronous and caching rules for Laravel — idempotent queued jobs with retries and backoff, domain events for side effects, queue separation and failure handling, deterministic cache keys with event-driven invalidation, and scheduled tasks that queue rather than block. Use when writing or reviewing jobs, events, listeners, queue configuration, caching or scheduled tasks, or when work is duplicated, lost, or blocking a request./laravel-engineeringLaravel implementation discipline for tracing context, reusing present contracts, keeping code simple, preserving failures, and verifying the changed critical path. Use when implementing, refactoring, debugging or reviewing Laravel code where callers, configuration, data flow or proof of correctness may be unclear./laravel-patternsPlacement rules for domain-driven Laravel applications — when to create an Action, Service, Repository, Query Class or Value Object, and when to just use Eloquent. Use when writing, reviewing or refactoring Laravel code that touches application structure, data access, domain boundaries or class placement. Triggers on questions like "where should this live", "should this be a service", "do I need a repository", or any new class in app/Domain./laravel-rest-apiREST API and HTTP-edge rules for Laravel — authorization before the domain runs, validation and DTO construction in Form Requests, scoped route model binding for nested resources, JSON output through Resources, thin controllers, and domain exceptions mapped to status codes centrally. Also covers outbound calls — HTTP client timeouts, retries, status handling and pooling. Use when writing or reviewing routes, controllers, form requests, API resources, policies, exception handling, or any call to a third-party API in a Laravel application./laravel-testingTest strategy for a layered Laravel application — which test style fits each layer, hand-written fakes over mocks, real-database tests for Query Classes and Repositories, pure tests for Value Objects, and feature tests that assert authorization, payload shape and query counts. Use when writing or reviewing Laravel tests, deciding what to fake, diagnosing a flaky or slow suite, or setting a project's testing conventions.Other plugins' skills for the same job