In this video, Justin demonstrates how to write a one-to-one relationship in Laravel, where one entry in the database relates to exactly one other record.
- [Instructor] We'll start now … building relationships for our Laravel Eloquent models. … Relationships in Laravel give us the ability … to then access and be able to talk to … and ask questions about that related model very easily. … One to one relationships are where one Laravel model … relates to only one other related record. … In our database we have a few examples of this. … But the one we've worked with most frequently … is how rooms relate to exactly one room type. … Let's see how to build up that relationship in Laravel … by opening up our room model at app, Room.php. … In our room model, the room has a field, … the room_type_Id field. … This room_type_Id field corresponds … to the matching type record. … To define this, we'll define a method … that will return this matching relationship. … Typically, this function is the name of the model. … And in the case where our relationship … only returns one record, we set it to be a singular … definition of that model name. … So in our case, write on line 21, …
- 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.