Skip to content

Commit

Permalink
You need to use clone
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Feb 7, 2025
1 parent 9ec2f6e commit ad4c533
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/Filament/App/Resources/ServerResource/Pages/ListServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ public function table(Table $table): Table

public function getTabs(): array
{
$baseQuery = auth()->user()->accessibleServers();
$all = auth()->user()->accessibleServers();
$my = (clone $all)->where('owner_id', auth()->user()->id);
$other = (clone $all)->whereNot('owner_id', auth()->user()->id);

return [
'my' => Tab::make('My Servers')
->badge(fn () => $baseQuery->where('owner_id', auth()->user()->id)->count())
->modifyQueryUsing(fn (Builder $query) => $query->where('owner_id', auth()->user()->id)),
->badge(fn () => $my->count())
->modifyQueryUsing(fn () => $my),

'other' => Tab::make('Others\' Servers')
->badge(fn (Builder $query) => $query->whereNot('owner_id', auth()->user()->id)->count())
->modifyQueryUsing(fn (Builder $query) => $query->whereNot('owner_id', auth()->user()->id)),
->badge(fn () => $other->count())
->modifyQueryUsing(fn () => $other),

'all' => Tab::make('All Servers')
->badge($baseQuery->count()),
->badge($all->count()),
];
}
}

0 comments on commit ad4c533

Please sign in to comment.