Spatie Roles & Permissions with Multi Tenancy

Hi all, this is my first question here. I am programming a training multi tenancy app wit spatie roles and permissions plugin and multi-tenancy filament option. Mi issue is about this error. I am completely blocked... In my AdminPanelProvider I'd set up tenant such this
->tenant(Team::class, ownershipRelationship: 'teams')
->tenant(Team::class, ownershipRelationship: 'teams')
No description
15 Replies
Kerchack
Kerchack11mo ago
Kind of this issue here. How can implement Spatie Roles and Permissions with multi tenancy Team model? Edit: If it helps, this is my flare link > https://flareapp.io/share/87nYz6DP
Flare
The model [Spatie\Permission\Models\Role] does not have a relationship named [team]. You can change the relationship being used by passing it to the [ownershipRelationship] argument of the [tenant()] method in configuration. You can change the relationship being used per-resource by setting it as the [$tenantOwnershipRelationshipName] static pro...
Kerchack
Kerchack11mo ago
Can anyone help with this? 😦
Patrick Boivin
Patrick Boivin11mo ago
Looks like you will need to extend the Spatie\Permission\Models\Role model to implement the team() relationship
Kerchack
Kerchack11mo ago
Will take a look and comment @pboivin Mmmm, the weird thing is that Role is related to User, not tenant
Patrick Boivin
Patrick Boivin11mo ago
Are you trying to manage the roles in Filament?
Kerchack
Kerchack11mo ago
Yep, I've installed plugin from fillament website related to plugins and I try to implement with teams. These are my basics
Patrick Boivin
Patrick Boivin11mo ago
I think that's it. You need the team() relationship on the Role model if you are managing it in a Panel with tenancy.
Kerchack
Kerchack11mo ago
But don't know what kind of relation implement in tenant() function
Patrick Boivin
Patrick Boivin11mo ago
Do you have any other model and resource in this Panel? Edit: it's team() not tenant(), my bad
Kerchack
Kerchack11mo ago
Let me explain what I did and I have. First of all installed filament and set up this plugin > https://filamentphp.com/plugins/tharinda-rodrigo-spatie-roles-permissions. All good with this Create an user, create a SuperAdmin Role and then asociate user to role Next steps, implement multi tenancy
Patrick Boivin
Patrick Boivin11mo ago
Ok, I understand. So if this is an issue with the plugin specifically, you should ask in the channel (if there is one) or Github. Not all plugin authors are on Discord.
Kerchack
Kerchack11mo ago
oh, sounds good
Patrick Boivin
Patrick Boivin11mo ago
But just a note as to what I'm saying above: All your resources that are in a Filament Panel with tenancy need a relationship to the tenant. Here's a quick example:
class Page extends Model
{
// ...

public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}
}
class Page extends Model
{
// ...

public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}
}
Check with the plugin author to see if this relationship is already setup for you or not.
Kerchack
Kerchack11mo ago
humm, thank you Now I can view Role and Permission menu but now cannot associate role with user because of team_id error. Gonna investigate and in case create new help ticket. Thank you so much @pboivin