eloquent-relationships
Installation
SKILL.md
Eloquent Relationships
When to use
- The user has slow pages or a flood of queries from accessing a relationship
inside a loop and needs to eager load with
with(),load(), orloadMissing(). - The user needs a many-to-many association through a pivot table — users and
roles, posts and tags — with
belongsToManyand optional pivot columns. - The user needs to relate two Eloquent models — a user has many posts, a post belongs to a user, an order has one invoice.
- The user needs one model (comments, images) to belong to several parent types
and reaches for
morphTo/morphManypolymorphic relations.