© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
charleswilfriedk

Summarize Sum of a calculated field

Hi! I'm trying to show the sum of a calculated attribute.
I have a Transaction model which has many Products. The pivot table has the quantity and the unit price for the product.

So i have the attribute amount which is calculated and appended to the transaction.
protected function amount(): Attribute
    {
        return Attribute::make(
            get: function () {
                return $this?->products->map(
                    fn ($product) => $product->pivot->quantity * $product->pivot->unit_price
                )->sum();
            },
        );
    }
protected function amount(): Attribute
    {
        return Attribute::make(
            get: function () {
                return $this?->products->map(
                    fn ($product) => $product->pivot->quantity * $product->pivot->unit_price
                )->sum();
            },
        );
    }

I can display the amount on my table with TextColumn('amount'), but when i try to add the summary i get a error that transactions.amount is not a field in the DB.
So my question is how do i make it use the eloquent model instead of a DB query?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

summarize calculated fields in footer
FilamentFFilament / ❓┊help
2y ago
Summarize Sum (quantity * price)
FilamentFFilament / ❓┊help
3y ago
How can I use summarize to add the sum of a calculated column in a table footer?
FilamentFFilament / ❓┊help
2y ago
Calculated input field in a form
FilamentFFilament / ❓┊help
2y ago