Create tenant menu

I'm trying to limit the number of tenants that a user can create, I have this code inside TeamPolicy:
public function create(): bool
{
$user = Auth::user();
$tenants = $user->team;
if (count($tenants) < Filament::getTenant()->allowedTenants()) {
return auth()->user()->role->name === 'administrador';
}
return false;
}
public function create(): bool
{
$user = Auth::user();
$tenants = $user->team;
if (count($tenants) < Filament::getTenant()->allowedTenants()) {
return auth()->user()->role->name === 'administrador';
}
return false;
}
The problem is, when the user attempts to create a new tenant (http://localhost/admin/new), the following code is returning null...
Filament::getTenant()
Filament::getTenant()
Any ideas?
6 Replies
Tim van Heugten
Tim van Heugten12mo ago
Why are you storing the allowed number of tenants on the tenant model? The code returns null because the create new page happens on a route without tenant awareness (slug/id).
ingmontoya
ingmontoyaOP12mo ago
The allowed number of tenants it's being stored on plan's model, that is a relationship between tenants and plans... how Can I do to make that rout aware of tenancy ?
Tim van Heugten
Tim van Heugten12mo ago
Its weird to have a tenant limit on a plan, while a plan is linked to a tenant. What if a user is linked to two tenants, both have a plan, one has a limit of one tenant and the other of three tenants? This is a very odd pattern.
ingmontoya
ingmontoyaOP12mo ago
you are right, but then how you'd handle plans in multitenancy? linked to users? what if a user can invite user to his tenant?
Tim van Heugten
Tim van Heugten12mo ago
No it’s very common to have the plan on the tenant and set feature limits etc based on the plan. However, usually you can create unlimited tenants but you would need a plan for each tenant to use features. Limiting the number of users per tenant for example is very common.
ingmontoya
ingmontoyaOP12mo ago
thanks!
Want results from more Discord servers?
Add your server