In my application, an organization has multiple events, and a user can have multiple roles in different events, Until now it's all good I can just do a pivot relation btw user_id, role_id, event_id
, But the problem is that I have some roles that are focused to the organization ex: Owner, Admin
and they're not related to the event. And therefore the previous DB structure cannot fix my problem cuz it's limited to users having roles in an event.
I've tried going for a polymorphic relationship which basically means a user can have a role either in an event or an organization like so: user_id, role_id, entity_id, entity_type
, But it's a lot of work and I don't know if it's the ideal solution.
What I've tried :
The one solution that I found is working with spatie's permissions package which supports teams.
So basically a user can have a role in an event, also a user can have permission in an event, So I figured that I work with the organization's scope instead of the event's scope and then give permission to the user to access a specific event. Ex: I invite a user to the organization
to be an Admin
and then give him the right (permission) to manage a specific event or multi events.
This seems to work, but the problem with it is that I'm limited to assigning one role to the user in that organization which means in all of the events, Cuz now the DB relationship is :
user_id, role_id, organization_id
.
Is there any way I can assign diffrent roles in diffrent events for the user, along with the ability to assign some roles outside of the events for some users ?