F
Filamentβ€’5mo ago
King Dice

Summarize course revenue

So I have a Course model and an Enrollment model. each Course has a fee. the Course model has a function that calculates the revenue like so:
public function getRevenueAttribute()
{
return $this->enrollments()->where('is_paid', true)->count() * $this->cost;
}
public function getRevenueAttribute()
{
return $this->enrollments()->where('is_paid', true)->count() * $this->cost;
}
and I am displaying that data in my table:
TextColumn::make('revenue')
->state(fn ($record) => $record->revenue)
->numeric(),
TextColumn::make('revenue')
->state(fn ($record) => $record->revenue)
->numeric(),
I want to display the sum of all course revenues at the bottom of my table but adding this didn't help:
->summarize(Sum::make())
->summarize(Sum::make())
instead I get this error
No description
3 Replies
Hurruwa
Hurruwaβ€’4mo ago
Haya, have you found a way to solve this yet? Im facing the same issue. Thanks in advance
LeandroFerreira
LeandroFerreiraβ€’4mo ago
This will only work with data directly from your table, not with custom model attributes, I believe
Hurruwa
Hurruwaβ€’4mo ago
Ok, thanks, ill find another way to deal with this. Thansk anyhow. πŸ˜‰
Want results from more Discord servers?
Add your server