Skip to content

Commit

Permalink
show count of items on location widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Flatroy committed Jun 25, 2024
1 parent 8380c37 commit 0f38324
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\LocationResource\Pages;

use App\Filament\Resources\LocationResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewLocation extends ViewRecord
Expand Down
6 changes: 5 additions & 1 deletion app/Filament/Widgets/Locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Tables\Columns\Layout\Stack;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Builder;

class Locations extends BaseWidget
{
Expand All @@ -19,12 +20,15 @@ public function table(Table $table): Table
{
return $table
->query(LocationResource::getEloquentQuery()->where('parent_id', null))
->modifyQueryUsing(fn (Builder $query) => $query->withCount('items'))
->defaultPaginationPageOption(15)
->defaultSort('created_at', 'desc')
->columns([
Stack::make([
Tables\Columns\TextColumn::make('name')
->searchable()->sortable(),
->searchable()
->suffix(fn (Location $record
): string => $record->items_count > 0 ? ' ('.$record->items_count.' items)' : ''),
]),
])
->contentGrid([
Expand Down

0 comments on commit 0f38324

Please sign in to comment.