eloquent-best-practices
Best practices for Laravel Eloquent ORM including query optimization, relationship management, and avoiding common pitfalls like N+1 queries.
By iserter · 1,232 installs
npx skills add iserter/laravel-claude-agents --skill eloquent-best-practices
Source repository · Upstream listing
Eloquent Best Practices
Query Optimization
Always Eager Load Relationships
Select Only Needed Columns
Use Query Scopes
Relationship Best Practices
Define Return Types
Use withCount for Counts
Mass Assignment Protection
Use Casts for Type Safety
Chunking for Large Datasets
Database Level Operations
Use Model Events Wisely
Common Pitfalls to Avoid
Don't Query in Loops
Don't Forget Indexes
Prevent Lazy Loading in Development
Checklist
[ ] Relationships eagerly loaded where needed
[ ] Only selecting required columns
[ ] Using query scopes for reusability
[ ] Mass assignment protection configured
[ ] Appropriate casts defined
[ ] Indexes on foreign keys and query columns
[ ] Using database level operations when possible
[ ] Chunking for large datasets
[ ] Model events used appropriately
[ ] Lazy loading prevented in development