I need to use pivot table's id as a foreign key in another table.
for example i have following tables:
users: id, username, ...
places: id, placename, lat, lng, ...
place_user: id, user_id, place_id
routes: place_user_id, lat, lng, inserted_at.
so when user says I am going to that place, I have a new entry in place_user table and start to log the route he takes to get there. So for each place_user entry i have many entries in routes table.
what is the correct way of doing this kind of relationship using eloquent? Should I create a model for the pivot table?
I have tried to solve my problem by the following solution but no luck: https://github.com/laravel/framework/issues/2093#issuecomment-39154456 and posted a comment there https://github.com/laravel/framework/issues/2093#issuecomment-58187802
any suggestions will be appreciated.
After lots of searching and trying different solutions I came up with the following solution:
User Model:
Place Model:
PlaceUser Model:
I have Changed name route to footprint to avoid problems with route class included in laravel.
Footprint Model:
In the end I get structure where I can make different queries like:
hope this helps