Summarizer On Custom Table

Hi all I am struggling with a custom table on filament v4. I need a SUM at the bottom fo the table much like we do on non customer tables. However I am getting the following error App\Filament\Clusters\Reports\Pages\InternetClients::getTableSummarySelectedState(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, null given, called in /Users/davidwhicker/Development/Herd/misce-filament/storage/framework/views/bcf55eaeae8fe2b8d0b210a2bb5b1d19.php on line 161 Here is my code:
return $table
->records(function (array $filters): Collection {
$invoices = Invoice::query()
->selectRaw('sum(sub_total) as sub_total, sum(profit) as profit, YEAR(date) as year, COUNT(id) as count, AVG(sub_total) as average , client_id')
->with('client')
->whereRelation('client', 'origin', 'internet')
->groupByRaw('year, client_id')
->orderBy('year', 'desc')
->get()
->toArray();

return collect($invoices)
->when(
filled($year = $filters['year']['value'] ?? null),
fn (Collection $data): Collection => $data->where(
'year', $year
),
);
}
)
->columns([
TextColumn::make('profit')->numeric(decimalPlaces: 0)->summarize([Sum::make('profit')]),
])
->filters([
SelectFilter::make('year')->options(Years::currentAndPreviousYears(5))->default(date('Y')),
], layout: FiltersLayout::AboveContent);
return $table
->records(function (array $filters): Collection {
$invoices = Invoice::query()
->selectRaw('sum(sub_total) as sub_total, sum(profit) as profit, YEAR(date) as year, COUNT(id) as count, AVG(sub_total) as average , client_id')
->with('client')
->whereRelation('client', 'origin', 'internet')
->groupByRaw('year, client_id')
->orderBy('year', 'desc')
->get()
->toArray();

return collect($invoices)
->when(
filled($year = $filters['year']['value'] ?? null),
fn (Collection $data): Collection => $data->where(
'year', $year
),
);
}
)
->columns([
TextColumn::make('profit')->numeric(decimalPlaces: 0)->summarize([Sum::make('profit')]),
])
->filters([
SelectFilter::make('year')->options(Years::currentAndPreviousYears(5))->default(date('Y')),
], layout: FiltersLayout::AboveContent);
I would really appreciate any help if anyone has a moment as I need totals on quite a few custom tables. It could be a simple SQL / PHP issue my end as opposed to a Filament restriction.
Solution:
Maybe its a bit late but i posted a quick fix in here: https://github.com/filamentphp/filament/issues/17286...
GitHub
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Package filament/filament Package Version v4.0.0 Laravel Version v12.23.1 Livewire Version v3.0.0 PHP Version PHP 8.4.11 Problem description When declaring a table either through the Widget menu or...
Jump to solution
2 Replies
David | Fortune Validator
Perhaps there is a special way to sum on data on a custom table that I’m missing. Pretty sure it’s not in the docs on the custom data section
Solution
muesker
muesker2w ago
Maybe its a bit late but i posted a quick fix in here: https://github.com/filamentphp/filament/issues/17286
GitHub
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Package filament/filament Package Version v4.0.0 Laravel Version v12.23.1 Livewire Version v3.0.0 PHP Version PHP 8.4.11 Problem description When declaring a table either through the Widget menu or...

Did you find this page helpful?