Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

janthoegersen's avatar

Fake model relationship

I have a project model where I want to associate roles and then users. The roles is a subset of the system roles (Spatie Permission) I have a relation table (Project Roles) with the subset of roles pointing to Spatie Roles. Then I have a Project Role Resources pivot table where I link users and their role to a project.

My challenge is that I can't figure out how I can jump to the associated users trough the Project Roles table as it has no relation with the projects. All projects will have the same subset so the table acts more like a filter.

What I want to archive is something like this: $ProjectRoles = Project->Roles (Getting the subset of system roles) foreach ($ProjectRoles as role) $role->users (Getting the associated users)

If the roles was not a subset of system roles, then it would be easy. But the "fake relationship" kills me...

Any help or better ideas are highly appreciated.

0 likes
1 reply
kossa's avatar

I had almost the same issue, for my cas I added new columns in projects(belongs to), in your case is you have many to many use a pivot table.

For query, for complicate model, I use DB query directly 😊

Please or to participate in this conversation.