O'Reilly logo

Learning Laravel's Eloquent by Francesco Malatesta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

More power – polymorphic relationships

Probably, you are thinking that Eloquent is cool and very powerful.

Well, yes, it is. However, sometimes, hasMany() or belongsToMany() isn't enough. In some situations during your development flow, you will have to deal with more complex relationships that could involve more than two entities.

So, as a last part of this chapter, I will talk about polymorphic relationships. As usual, even if they aren't complex to learn, I will cover them with many detailed examples, in order to let you fully understand the entire concept.

Let's start from the simple polymorphic relationship.

A simple polymorphic relationship

A simple polymorphic relationship can be used when you have an entity that can belong to either one entity ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required