public function table(Table $table): Table
{
return $table
->defaultGroup('descr')
->columns([
TextColumn::make('punti')
->summarize(Summarizer::make()
->label('Total Points')
->using(function ($query) {
$totalPoints = $query->sum('punti'); // Sum of all points
$maxPoints = $query->value('punti_max'); // Fetches a single value of punti_max (since it is the same for all records in the same group)
return $maxPoints !== null ? min($totalPoints, $maxPoints) : $totalPoints;
}))
public function table(Table $table): Table
{
return $table
->defaultGroup('descr')
->columns([
TextColumn::make('punti')
->summarize(Summarizer::make()
->label('Total Points')
->using(function ($query) {
$totalPoints = $query->sum('punti'); // Sum of all points
$maxPoints = $query->value('punti_max'); // Fetches a single value of punti_max (since it is the same for all records in the same group)
return $maxPoints !== null ? min($totalPoints, $maxPoints) : $totalPoints;
}))