In this video, Justin demonstrates how to write a many-to-many relationship in Laravel, where multiple entries in the database relate to multiple other records elsewhere in the database.
- [Instructor] Our most complex relationship … is a many to many relationship. … In a many to many relationship, … we need to go from many records in one table … to many other records in another table. … These relationships are defined using a join table, … where you have a collection of records … that has a matching ID pairs from each other table. … This middle table acts then … to join those two other tables together. … This is a classic many to many relationship, … and we actually have one in our database … between bookings and user. … A user has many bookings, obviously, … because a user can have multiple bookings at a hotel, … and each booking is designed such that … multiple users could be associated … with each booking if need be. … Let's fill out the bookings model … and see this many to many relationship in action. … We'll open up the bookings model … at app, Booking.php. … Let's define first some of the relationships … that we've already previously seen. … We'll define a relationship from the booking to the room. …
- Exploring Laravel
- Setting up simple authentication
- Controllers and routes
- Create and index view
- Show, edit, and destroy views
- Writing scopes in Laravel Eloquent
- Creating one-to-one relationships
Skill Level Beginner
MVC Frameworks for Building PHP Web Applicationswith Drew Falkman2h 57m Intermediate
Ajax with PHP: Add Dynamic Content to Websiteswith Kevin Skoglund3h 37m Intermediate
What you should know1m 52s
2. Starting Your Project
3. The Create and Index Views
4. The Show, Edit, and Destroy Views
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.