Summarize Relationship aggregate

Hi, is there a way to custom summarize a relationship sum aggregate? Something like:
TextColumn::make('totalHours')
->label('Total Hours')
->state(fn(Model $record) =>
$record->payroll_items_sum_reg_hours +
$record->payroll_items_sum_ot_hours)
->summarize(Summarizer::make()
->label('Total')
->using(fn(Builder $query): string =>
$query->payroll_items_sum_reg_hours + $query->payroll_items_sum_ot_hours)),
TextColumn::make('totalHours')
->label('Total Hours')
->state(fn(Model $record) =>
$record->payroll_items_sum_reg_hours +
$record->payroll_items_sum_ot_hours)
->summarize(Summarizer::make()
->label('Total')
->using(fn(Builder $query): string =>
$query->payroll_items_sum_reg_hours + $query->payroll_items_sum_ot_hours)),
This throws a: Undefined property: Illuminate\Database\Query\Builder::$payroll_items_sum_reg_hours How could I access the relationship in the summarizer?
4 Replies
Somebody
Somebody15mo ago
did u import the builder class?
AmauryCid
AmauryCidOP15mo ago
Sure! But I guess Query\Builder doesn't work as Eloquent\Builder, so it can access Eloquent methods
Somebody
Somebody15mo ago
what eloquent method do u need? I believe it is query / builder as it uses less memory which is important when dealing with large number of records
AmauryCid
AmauryCidOP15mo ago
I need the sum method, you could see what I’m trying to do in my example code above.
Want results from more Discord servers?
Add your server