From the course: Laravel Essential Training
Unlock the full course today
Join today to access over 25,000 courses taught by industry experts.
What are Eloquent relationships? - Laravel Tutorial
From the course: Laravel Essential Training
What are Eloquent relationships?
Database tables are often related to one another. For example, a post can have many likes, a student can take many subjects, and in our case, a user can have many notes. When you have too many tables and multiple relations, querying with 'where' clauses like get the notes where belongs to user and so on can get tricky and complex. Eloquent makes it easy to work with such relationships and also supports several types of relationships like one to one, one to many, one of many, many to many, and custom types, too. In our case, the user model has a one to many relationship with the note model. With this basic knowledge, let's look at how to define Eloquent relationships and then use them to query and save the models.