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 Heugten6mo 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
ingmontoya6mo 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 Heugten6mo 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
ingmontoya6mo 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 Heugten6mo 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
ingmontoya6mo ago
thanks!
Want results from more Discord servers?
Add your server
More Posts
How do I make EditProfile.php use more width please?I am using custom editprofile.php with Filament panel. The EditProfile page is using small width, PlHeader Table SortByI cannot for the life of me figure out in the docs where to replicate the sort by found on this pageFilament form - instead of hidden how to use disable?If Select with "building_id" is not selected in UI it explodes. So i use ->hidden on "floors" to aI am using filament/spatie-laravel-media-library-plugin but having an issue showing the first imageI was able to upload multiple images in a collection() with no issues at all, but what I am trying tImageColumnand FileUpload , so i upload the file ( image ) FileUpload::make('filepath')->disk('local')->directodeferLoading Placeholder TextIs it possible to have a default row much like with emptyStateHeading but for when the table is loadAuthorization on Repeater Form field relationIs possible to add authorization to form fields. I know I can add a hide() and pass a closure that Allow reorderable without fillable column?Good evening everyone! I am somewhat stuck on adding reorderable. I noticed that I am required to aThe GET method is not supported for route livewire/update. Supported methods: POST.I've been getting this error very randomly, some users in the web app get it while others don't and Is there any library to scan QRcode? after generate it i want to scann itIm looking for library or pluging that help to do scann QRcode to check or delete or log in by using