Support the ongoing development of Laravel.io →
Database Eloquent Architecture

Hi, I need to use pivot tables 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?

update: 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 appriciated.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

torniker torniker Joined 7 Oct 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2025 Laravel.io - All rights reserved.