O'Reilly logo

Mastering Laravel by Christopher John Pecoraro

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

Eloquent relations

Relationships such as one-to-one, one-to-many (or many-to-one), and many-to-many are familiar to database programmers. Laravel's Eloquent has brought these concepts into an object-oriented environment. Additionally, Eloquent has even more powerful tools such as polymorphic relations, where entities can be related to more than one other entity. In the following examples, we will see the relationship between accommodations, rooms, and amenities.

Eloquent relations

One-to-one

The first relation is one-to-one. In our example software, we can use the example of a room in our accommodation. A room may only (at least easily) belong to one accommodation, ...

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