Skip to Main Content
Laravel 5 Essentials
book

Laravel 5 Essentials

by Martin Bean
April 2015
Beginner content levelBeginner
144 pages
3h 13m
English
Packt Publishing
Content preview from Laravel 5 Essentials

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Laravel: A beginner's guide to application development with Laravel 5.3

Beginning Laravel: A beginner's guide to application development with Laravel 5.3

Sanjib Sinha
Laravel 5.x Cookbook

Laravel 5.x Cookbook

Terry Matula, Alfred Nutile

Publisher Resources

ISBN: 9781785283017Supplemental Content