Not sure what you mean by associating a Role with an Event; are you saying Event has an Organizer or Event is an Organizer?
Associate a role with a model
I'm trying to figure out the best way to associate a role with a second model in addition to User. That is, I have an "organizer" role that I want to associate with an "Event" model, and a "manager" role that I want to associate with a "Group" model. I'm using Spatie's permissions package; "organizer" and "manager" are both user roles that carry various permissions. But what's the best way to associate these roles with another model? Any advice would be greatly appreciated.
@maparfitt in that case you most likely need an organizer_id column, and an organizer relationship on the Event Model:
public function organizer()
{
return $this->belongsTo(User::class);
}
The foreign key is pointing to a User; not the Role. It will be up to your business logic to associate a User with the appropriate Role.
Please or to participate in this conversation.