0007-eloquent-best-practices

Community

Speed up Laravel Eloquent queries safely

AuthorMrJmpl3
Version1.0.0
Installs0

System Documentation

What problem does it solve?

It solves slow and inefficient Laravel Eloquent performance caused by common ORM anti-patterns like N+1 queries, over-fetching data, and missing indexes.

Core Features & Use Cases

  • Query optimization: Eager loading, selecting only needed columns, reusable query scopes, and chunking/lazy processing for large datasets (e.g., rendering feeds without degrading response times).
  • Relationship correctness: Clear relationship method return types and efficient count loading with withCount to avoid per-model extra queries (e.g., showing post comment counts in listings).
  • Production safety and maintainability: Mass assignment protection via fillable/guarded, type-safe casts, database-level updates/increments, sensible model events, and preventing lazy loading in development (e.g., reducing accidental data bugs and performance regressions).

Quick Start

Ask the AI to review your Laravel Eloquent models and queries and rewrite them to eliminate N+1 issues, reduce selected columns, and add withCount/with eager loading where appropriate.

Dependency Matrix

Required Modules

None required

Components

Standard package

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: 0007-eloquent-best-practices
Download link: https://github.com/MrJmpl3/codex_____data_____configuration/archive/main.zip#0007-eloquent-best-practices

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.