Relation manager not allowing duplicates

Hi there, I have roles and users in my app. In the pivot table, there is an optional "assignable" morph, so that the role can be against another entity, such as my Location model... "A user has a role for this location..." I should be able to attach multiple roles to a user, as long as the assignable is different, so the user can have the same role for multiple locations, but I can't seem to figure out how to achieve this? In the relation manager attach action, the role is removed from the selection as soon as it's been assigned once. If I hard code the role options to always displace all, if i attach multiple roles to a user with different "assignables", when I "detach" one record, it detaches all relations which have the same user_id, role_id... Any help? I've attached some files, and my relationships include the id pivot:
// user model role relation
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class)
->withPivot('id', 'assignable_type', 'assignable_id')
->withTimestamps();
}

// role model users relation
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)
->withPivot('id', 'assignable_type', 'assignable_id')
->withTimestamps();
}
// user model role relation
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class)
->withPivot('id', 'assignable_type', 'assignable_id')
->withTimestamps();
}

// role model users relation
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class)
->withPivot('id', 'assignable_type', 'assignable_id')
->withTimestamps();
}
Thanks!
1 Reply

Did you find this page helpful?