Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent

I'm in pivot hell. Please help. I have 3 tables I need to pivot and can't figure out a clean way to model this relationship.

Table 1: Users

Table 2: Projects

Table 3: Roles

The relationship is this. A user has many roles on a project.

For example a user could be a writer, an editor, a director on Project X. A user can be one or many roles on a project.

So let's say I have a list of users - say from a production company. This is not part of the relationship. It is just a separate list of user ids.

How can I get all projects where those users are editors on?

Last updated 2 years ago.
0

This is a frequent problem. It is known as a four table relation (3 + pivot).
I think the best solution is to add an id column to the pivot table and handle it as a model.

0

Thanks I came to the same conclusion

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.