Support the ongoing development of Laravel.io →
Database Laravel Architecture
Last updated by @amipax 3 months ago.
0

I think doing a more abstract thought process helps in these situations. Lets look at the real-life problem which you are trying to model: You have a student, who approaches the instructor and asks when they will have their next lesson? The instructor takes a notebook, they agree on a date and time and reserve a car. In essence, you need to mimic the notebook as an aggregation column for you database. So it would have fields like ID, InstructorID, StudentID, CarID, DateBegin, DateEnd. Now, what we want to avoid, is a car being overbooked, so I would also add a boolean field to the Car Table, which says if the car is currently in use/free, and also do a check during registration whether the car is free in the period of time that is being attempted.

0

In this case each Instructor has an assigned Car, so he/she shouldn't worry about it unless it's broken down. It can be confusing to have 4 foreign keys on a pivot table and not knowing how to make the model relationships.

Last updated 3 months ago.
0

Sign in to participate in this thread!

Cloudways

Your banner here too?

Rodrigo Rodrigo amipax Joined 20 Apr 2022

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.