Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

Eloquent Relationships Deep Dive

In this series, we'll unlock the full power of Eloquent relationships, from the basics of hasOne and belongsToMany to polymorphic magic and performance tuning. Whether you're building a blog or architecting a multi-tenant SaaS, understanding how your models connect is critical. Let's get relational.

Progress

Series Info

Episodes
8
Run Time
2h 11m
Difficulty
Intermediate
Last Updated
Nov 26, 2025
Version
Latest

Series Episodes

  1. Episodes (8)
    1. One-to-One Relationships

      Learn how to set up and enforce one-to-one relationships using Eloquent. We'll walk through the database constraints, model definitions, default values, and how to work with related data efficiently.
    2. One-to-Many Relationships

      In this episode, we explore Eloquent's one-to-many relationships using a practical example where each user can have many tasks. You'll learn how to set up the database schema, define Eloquent relationships, seed related data, query and eager load tasks—including how to filter eager-loaded relationships for more precise results.
    3. Many-to-Many Relationships

      Learn how to manage many-to-many relationships using Eloquent and pivot tables. We'll explore belongsToMany, pivot data, and how a custom pivot model can bring structure and logic to your relationship layer.
    4. Has Many Through

      In this episode, you'll learn how Eloquent's hasManyThrough relationship lets you access deeply related data through an intermediate model. We'll walk through a practical example and show how it simplifies complex queries into a single, expressive relationship.
    5. Polymorphic Relationships

      Learn how to set up and use polymorphic relationships, where a single model can belong to multiple other models using one database table. This episode covers both one-to-one (morphOne) and one-to-many (morphMany) examples with practical relationships like descriptions and notes.
    6. Many-to-Many Polymorphic Relationships

      This episode covers how to associate a single model, like Tag, with multiple other models using a single polymorphic pivot table. You'll learn how to define and use morphToMany and morphedByMany relationships to build flexible features like tagging across your application.
    7. Eager Loading and Aggregate Functions

      Learn how to optimize your Eloquent queries by using eager loading techniques. This episode covers constrained eager loading, lazy eager loading, counting related models, and running aggregate queries like withSum and withAvg.
    8. Smarter Eager Loading

      Solve the N+1 problem forever while also taking advantage of Eloquent's lazy-loading feature.

Continue Learning