Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Laravel 5 Essentials

You're reading from   Laravel 5 Essentials Explore the fundamentals of Laravel, one of the most expressive and robust PHP frameworks available

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781785283017
Length 144 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Martin Bean Martin Bean
Author Profile Icon Martin Bean
Martin Bean
Arrow right icon
View More author details
Toc

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 relations

Here, we will look through them with an example of each.

One-to-one

Sometimes, you may want to split data across multiple tables for ease of management, or because they represent two different parts of one entity. A common example is a user...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image