Aug 20, 2024
0
Level 6
How to fetch activeTab for visibility in filter (resource)
I want to show the role filter on the admin tab only
So I have this table tab in ListUsers.php
public function getTabs(): array
{
return [
'all' => Tab::make(),
'admin' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('role', [Role::SuperAdmin, Role::Admin, Role::Csr, Role::Auditor])),
'customer' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->where('role', Role::Customer)),
];
}
```
and in the UsersResource I have this filter
Tables\Filters\SelectFilter::make('role') ->options([ Role::SuperAdmin->value => 'Super Admin', Role::Admin->value => 'Admin', Role::Csr->value => 'Csr', Role::Auditor->value => 'Auditor', ]) ->label('Role') ->visible(fn () => request()->get('activeTab') === 'admin')
it will only work if you refresh the page but if you just do clicking it will not working
->visible(fn () => request()->get('activeTab') === 'admin')
Please or to participate in this conversation.