F
Filamentβ€’11mo ago
harps

GetTabs actions

In a scenario where I'm using soft deletes I have an active and inactive tab but my bulk archive (delete) action shows on both active and inactive header. Is there a way to only show the archive (delete) action on the active tab?
Solution:
This should work
Action::make()
->visible(fn ($livewire) => $livewire->activeTab == 'active')
Action::make()
->visible(fn ($livewire) => $livewire->activeTab == 'active')
...
Jump to solution
7 Replies
Sjoerd24
Sjoerd24β€’11mo ago
'archive' => Tab::make(__('Archive')) ->modifyQueryUsing(function ($query) { return $query->onlyTrashed(); })
harps
harpsOPβ€’11mo ago
Thanks @Spoof444 but that creates the tab? I already have two tabs but the bulk action "Archive" appears on both tabs when it does nothing on the inactive tab because the items are already archived.
public function getTabs(): array
{
return [
'active' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereNull('deleted_at')),
'inactive' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereNotNull('deleted_at')),
];
}
public function getTabs(): array
{
return [
'active' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereNull('deleted_at')),
'inactive' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->whereNotNull('deleted_at')),
];
}
Sjoerd24
Sjoerd24β€’11mo ago
if you have in your model use Softdeletes, that shouldnt all be neccesary, then you could use: public function getTabs(): array { return [ 'active' => Tab::make() //this should now show the correct unfilters results 'inactive' => Tab::make() ->modifyQueryUsing(fn (Builder $query) => $query->onlyTrashed(), ]; }
harps
harpsOPβ€’11mo ago
Thanks for the tip @Spoof444 but that doesn't solve the issue I want to solve. I want different bulk actions in each tab For example there is no need to have the "Archive" action/button in the header of the inactive tab.
Solution
Dennis Koch
Dennis Kochβ€’11mo ago
This should work
Action::make()
->visible(fn ($livewire) => $livewire->activeTab == 'active')
Action::make()
->visible(fn ($livewire) => $livewire->activeTab == 'active')
Sjoerd24
Sjoerd24β€’11mo ago
Ah didnt understand you correctly @harps . Dennis example looks perfect for you πŸ‘
harps
harpsOPβ€’11mo ago
Thanks @Dennis Koch that was it.
Want results from more Discord servers?
Add your server