What problem does it solve?
This Skill streamlines database interactions within Laravel applications by providing comprehensive guidance and best practices for using the Eloquent ORM, preventing common pitfalls like N+1 query problems and ensuring efficient data handling.
Core Features & Use Cases
- Model Definition: Understand and create Eloquent models, including mass assignment protection (
$fillable, $guarded).
- Relationships: Define and utilize all relationship types (One-to-One, One-to-Many, Many-to-Many, Polymorphic, Through).
- Query Optimization: Implement eager loading (
with(), load()) to prevent N+1 queries and use scopes for reusable query logic.
- Data Casting: Properly cast attributes for type safety and use accessors/mutators for data transformation.
- Use Case: When building a blog, you'll use this Skill to define the
Post model, establish its belongsTo relationship with the User model (author), and ensure posts are efficiently loaded with their author data using eager loading.
Quick Start
Use the laravel-eloquent skill to define a basic Eloquent model for a 'Product' with 'name' and 'price' fields.