What problem does it solve?
This Skill provides a comprehensive guide to writing efficient, maintainable, and best-practice-compliant code for Laravel's Eloquent ORM and database interactions, preventing common pitfalls like N+1 query problems and ensuring robust data management.
Core Features & Use Cases
- Eloquent Model Structure: Enforces a consistent and organized order for model properties, relationships, scopes, and methods.
- Relationship Management: Guides on defining and querying relationships effectively, including eager loading and existence checks.
- Query Optimization: Offers strategies to prevent N+1 issues, select only necessary columns, use chunking for large datasets, and leverage database-level operations.
- Migrations & Seeding: Outlines best practices for writing clear, rollback-friendly migrations and organizing seeders with factories.
- Use Case: When developing a feature that displays a list of users with their associated orders, this skill ensures you use
with('orders') to avoid performance degradation caused by the N+1 problem.
Quick Start
Use the laravel-eloquent-database skill to refactor the provided user model to follow best practices for Eloquent model structure.