Oleksandr
Error When Displaying Aggregated Data in Filament Resource Table
Hello everyone,
I need assistance with an issue, please. I have a model that requires data aggregation (calculating sums by group). Afterwards, I'd like to display these aggregated data in a resource table. To transform the data, I'm using Eloquent:
return $table->modifyQueryUsing(function (Builder $query) use ($today) {
$query->where('dt', '>=', $today)
->groupBy('hour')
->selectRaw('DATE_FORMAT(dt, "%H:00") as hour, SUM(rounded) as total_sum');
})
->columns([
Tables\Columns\TextColumn::make('hour'),
Tables\Columns\TextColumn::make('total_sum'),
]);
However, I'm encountering an error: "Filament\Resources\Pages\ListRecords::getTableRecordKey(): Return value must be of type string, null returned." I understand that ListRecords requires an ID value from the model's record. However, after data transformation, this ID value is no longer present.
Could you please advise on how to solve this issue or suggest a workaround?5 replies