Back Button Laravel
Eloquent Relationships

Eloquent Relationships

Eloquent make the process of interacting with your database tables as natural and intuitive as possible. It's vital that you recognize and understand six key relationship types. Let's review them all - one episode per relationship.

Beginner
6 episodes
1:25:45 hrs
6
Latest Episode in This Series

Added 1 year ago

Many to Many Polymorphic Relations

We've finally made it to the most intimidating of Eloquent relationships: many to many polymorphic. Don't worry;...

Watch
Eloquent Relationships

Eloquent Relationships

Eloquent make the process of interacting with your database tables as natural and intuitive as possible. It's vital that you recognize and understand six key relationship types. Let's review them all - one episode per relationship.

Begin
6
Latest Episode in This Series

Added 1 year ago

Many to Many Polymorphic Relations

We've finally made it to the most intimidating of Eloquent relationships: many to many polymorphic. Don't worry;...
Watch

Your Teacher | Jeffrey Way

https://laracasts.s3.amazonaws.com/avatars/jeffrey-avatar.jpg's avatar
Hi, I'm Jeffrey. I'm the creator of Laracasts and spend most of my days building the site and thinking of new ways to teach confusing concepts. I live in Orlando, Florida with my wife and two kids.
    1. EPISODE 1

      Run Time 11:42

      First up, we have "one to one" relationships. This is an easy one to picture in your head. What is one thing that a user might be associated with? What about a profile, or an address, or an avatar?

    2. EPISODE 2

      Run Time 11:05

      Now that we have "one-to-one" relationships locked and loaded, let's move on to our next Eloquent relationship: "one-to-many." What might be an example of something a user would have many of? What about posts, or projects, or tasks? You'll reach for this relationship constantly in your daily workflow.

    3. EPISODE 3

      Run Time 19:06

      Many to many relationships are a bit more confusing to understand. Let's break it down by reviewing the common "posts" and "tags" relationship. A one-to-one or one-to-many relationship isn't quite right here. A post will never own a tag. It can be associated with one, sure, but it doesn't own the tag. The same is true in reverse. When we encounter situations such as this, a "many-to-many" relationship is exactly what we need.

    4. EPISODE 4

      Run Time 9:05

      While not nearly as common, the hasManyThrough relationship, when necessary, can prove to be incredibly useful. This relationship type allows you to perform queries across long-distance relationships.

    5. EPISODE 5

      Run Time 14:30

      We've made it to the scariest of Eloquent relations: polymorphic. Don't worry! As with most things, the word is scarier than the technique. A polymorphic relationship allows a model to belong to any number of models on a single association. Let's demonstrate this with a practical example.

    6. EPISODE 6

      Run Time 20:17

      We've finally made it to the most intimidating of Eloquent relationships: many to many polymorphic. Don't worry; it's far simpler to understand than you might initially think. In this lesson, we'll construct a standard many-to-many relationship: a user can "like" a post. Then, we'll throw a wrench into the mix. What if a user can also "like" a comment? How might we restructure our existing structure to allow for this?