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;
    }

and I am displaying that data in my table:
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())

instead I get this error
image.png
Was this page helpful?