Guidance on Laravel Eloquent ORM best practices for query optimization, relationships, and avoiding N+1 queries.
- What it does
- This skill provides reference guidance and code examples for writing efficient Laravel Eloquent ORM code. It covers eager loading, column selection, query scopes, relationship return types, withCount, mass assignment protection, casts, chunking, database-level operations, model events, indexes, and lazy loading prevention. It produces explanatory snippets and a checklist rather than executable scripts.
- When to use it
- Use it when working with Laravel Eloquent models and queries, especially to optimize performance, fix N+1 query issues, or review relationship and mass assignment patterns. It is also useful as a checklist during code review of Eloquent-based code.
- Requirements
- No scripts or special tools are required; it is instructions and code examples only. A Laravel project with Eloquent is the assumed context.