Hi all, I got a situation that I cannot seem to solve.
I got the following setup
users (id)
companies (id)
roles (id, roleable_type, roleable_id) /// roleable in this example points to company but can also point to tenant
roles_users (role_id, user_id)
Now the tricky part
in my user I have companies(): BelongsToMany {} relation but I need to make an extra join for the roles OR roles_users table. I even extended BelongsToMany and got it working (got all companies) from the user. But now with inverse User::query()->has('companies') I find myself hacking BelongsToMany even further.
Hope anyone has experienced this before and can point me in the right direction.
By default, only the model keys will be present on the pivot model. If your intermediate table contains extra attributes, you must specify them when defining the relationship:
The issue isn't with the pivot table. The issue is that I need an additional pivot table where the relatedKey and relatedPivot key are both from different tables. So I need to join 4 tables together instead of the regular three tables.