Delete Tenant

I might know the answer already (No) but I might as well ask. Just to be sure. Is there a way, or is it even allowed to delete Tenants?
Solution:
If you are asking about how to go about this, look at this package. Its a feature of it. https://github.com/andrewdwallo/filament-companies...
GitHub
GitHub - andrewdwallo/filament-companies
Contribute to andrewdwallo/filament-companies development by creating an account on GitHub.
Jump to solution
24 Replies
Andrew Wallo
Andrew Wallo16mo ago
Good question
awcodes
awcodes16mo ago
What wouldn’t it be? Are you seeing any issues trying to do it.
tuto1902
tuto1902OP16mo ago
Well, let me explain: Is it allowed to have a ClinicResource so, lets say, an admin user can Add/Remove clinics I think my mind got stuck when I started thinking about the model relationships
Andrew Wallo
Andrew Wallo16mo ago
You probably just have to make sure the tenant_id is connected to all tables and use something like this:
$table->foreignId('company_id')->constrained()->cascadeOnDelete();
$table->foreignId('company_id')->constrained()->cascadeOnDelete();
tuto1902
tuto1902OP16mo ago
Right, but I can't do something like
php artisan make:filament-resource Company
php artisan make:filament-resource Company
Since the Company model would need a company relationship. Plus, (once created) that company would only belong to the Company you are currently working on. See? complete brain cramp 😵‍💫
Andrew Wallo
Andrew Wallo16mo ago
Not if you have multiple companies
awcodes
awcodes16mo ago
This is why path based tenancy sucks. Subdomains helps to keep it all in mental context. 😅
Andrew Wallo
Andrew Wallo16mo ago
Keep it so that one company a user has can't be deleted
awcodes
awcodes16mo ago
Why shouldn’t the company be able to be deleted and then cascade all its users?
Andrew Wallo
Andrew Wallo16mo ago
I mean yeah if a user belongs to the company being deleted then those users would be deleted as well... Thats why you need to make sure the user really wants to delete the company before they do it
tuto1902
tuto1902OP16mo ago
The question arises from this: I have a UserResource that an Admin can use to create new users. Inside, I have a multiple Select input tied to the companies relationship on that model. I added the createOptionForm, so I can create a new company on the fly. But now I'm thinking, what if the admin creates a company by mistake. Hence the need of a CompanyResource
Andrew Wallo
Andrew Wallo16mo ago
I mean yeah I would add the feature to be able to delete companies/tenants I'm going to I think its needed
tuto1902
tuto1902OP16mo ago
but riddle me this. When I create the Company resource I'm faced with this error when trying to access it:
The model [App\Models\Company] does not have a relationship named [company]
The model [App\Models\Company] does not have a relationship named [company]
With every other resource, the company relationship it's a belongsToMany(Company::class). Do I create a pivot table called company_company and have the Company model belong to itself?
Solution
Andrew Wallo
Andrew Wallo16mo ago
If you are asking about how to go about this, look at this package. Its a feature of it. https://github.com/andrewdwallo/filament-companies
GitHub
GitHub - andrewdwallo/filament-companies
Contribute to andrewdwallo/filament-companies development by creating an account on GitHub.
Andrew Wallo
Andrew Wallo16mo ago
The models should be similar to what is used in Filament v3 tenancy
tuto1902
tuto1902OP16mo ago
Interesting 🤔 I'll give it a try. Thanks for the help!
Andrew Wallo
Andrew Wallo16mo ago
Its similar to the way Jetstream works if you have ever used that.
tuto1902
tuto1902OP16mo ago
Never have I ever. But I like having to learn something new 👍
Andrew Wallo
Andrew Wallo16mo ago
Yep learning tenancy architecture takes a while to learn fluently. Good luck!
Andrew Wallo
Andrew Wallo16mo ago
@tuto1902 You can also download and try it out yourself with this package. https://github.com/andrewdwallo/erpsaas This may help you understand everything more..
GitHub
GitHub - andrewdwallo/erpsaas
Contribute to andrewdwallo/erpsaas development by creating an account on GitHub.
tuto1902
tuto1902OP16mo ago
Awesome! I'll look into it
Andrew Wallo
Andrew Wallo16mo ago
Let me know how it goes. Feel free to message me if you have any questions!
oRieN
oRieN10mo ago
I'm probably late to this post but something like this is what the OP needs
// File: App\Filament\Pages\Tenancy\EditTenantProfile.php

protected function getHeaderActions(): array
{
return [
Action::make('delete')
->requiresConfirmation()
->action(fn () => $this->tenant->delete()),
];
}
// File: App\Filament\Pages\Tenancy\EditTenantProfile.php

protected function getHeaderActions(): array
{
return [
Action::make('delete')
->requiresConfirmation()
->action(fn () => $this->tenant->delete()),
];
}
Want results from more Discord servers?
Add your server