F
Filamentβ€’6mo ago
Danny

Deleting a tenant with EditTeamProfile.php

I'm looking to add the ability to allow users to delete their own team but not their primary team (the first team they created). Could someone point me in the right direction for any example code for this? All I'm able to find is creating teams. This is what I've currently got in my EditTeamProfile class. However, the query to delete doesn't run. protected function getHeaderActions(): array { $user = auth()->user(); if ($this->tenant->id != $user->team_id) { return [ Actions\Action::make('Delete location') ->name('delete') ->icon('heroicon-m-x-mark') ->color('danger') ->requiresConfirmation() ->action(function () { DeleteAction::make() ->record($this->tenant) ->successRedirectUrl(route('filament.dashboard.pages.dashboard', [ 'tenant' => auth()->user()->team_id ] )); Notification::make() ->success() ->title('Location deleted') ->body('The location has been deleted.') ->send(); }), ]; } else { return []; } } Teams belong to many public function teams(): BelongsToMany { return $this->belongsToMany(Team::class, 'team_user'); } team_user cascades on delete $table->foreignId('team_id')->constrained()->on('teams')->onDelete('cascade'); Really appreciate any help any could offer as I'm not really sure how to resolve this. Again, if you could point towards some working code, I should be able to figure it out. Thanks πŸ˜„
Solution:
Got it! If anyone else is hitting their head with this. Here's how I solved it: ` protected function getHeaderActions(): array { $user = auth()->user();...
Jump to solution
1 Reply
Solution
Danny
Dannyβ€’6mo ago
Got it! If anyone else is hitting their head with this. Here's how I solved it: protected function getHeaderActions(): array { $user = auth()->user(); if ($this->tenant->id != $user->team_id) { return [ Actions\Action::make('Delete location') ->name('delete') ->icon('heroicon-m-x-mark') ->color('danger') ->requiresConfirmation() ->action(function (Team $team) { $this->tenant->delete(); redirect(route('filament.dashboard.pages.dashboard', [ 'tenant' => auth()->user()->team_id ])); Notification::make() ->success() ->title('Location deleted') ->body('The location has been deleted.') ->send(); }), ]; } else { return []; } }
Want results from more Discord servers?
Add your server