O'Reilly logo

Laravel 5 Essentials by Martin Bean

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

Relationships

When we built our application in Chapter 3, Your First Application, we made use of relationships. Each cat in our application was of a particular breed. However, instead of storing the name of the breed next to every individual cat and potentially having the breed repeating numerous times, we created a separate breeds table and each cat's breed was a value that referred to the ID of a record in that table. This gave us an example of two types of relationships: a cat belongs to a breed, but a breed can have many cats. This is defined as a one-to-many relationship.

There are other types of relationships, for each of which Eloquent provides good support:

  • One-to-one
  • Many-to-many
  • Has-many-through
  • Polymorphic relations
  • Many-to-many polymorphic ...

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