Agent skill
Laravel Eloquent
Advanced Eloquent ORM patterns for performance and query reuse.
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/eloquent
Metadata
Additional technical details for this skill
- labels
-
laravel eloquent orm database
- triggers
-
{ "files": [ "app/Models/**/*.php" ], "keywords": [ "scope", "with", "eager", "chunk", "model" ] }
SKILL.md
Laravel Eloquent
Priority: P0 (CRITICAL)
Structure
text
app/
└── Models/
├── {Model}.php
└── Scopes/ # Advanced global scopes
Implementation Guidelines
- N+1 Prevention: Always use
with()or$withfor relationships. - Eager Loading: Set strict loading via
Eloquent::preventLazyLoading(). - Reusable Scopes: Define
scopeNamemethods for common query filters. - Mass Assignment: Define
$fillableand use$request->validated(). - Performance: Use
chunk(),lazy(), orcursor()for large tasks. - Casting: Use
$castsfor dates, JSON, and custom types.
Anti-Patterns
- N+1 Queries: No lazy loading: Never query relationships in loops.
- Fat Models: No business logic: Models are for data access only.
- Magic Queries: No raw SQL: Use Query Builder or Eloquent.
- Select *: No excessive data: Select only required columns.
References
Didn't find tool you were looking for?