Table Column Relationship Sum, Avg, Max, Min, ext being ignored

I have model that consists of products. The products have a relationship of locationInventory that contain the inventory numbers for each location. On my Product Resource Table, I have a column like this:
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock')
->sum('locationInventory' , 'quantity_in_stock'),
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock')
->sum('locationInventory' , 'quantity_in_stock'),
Based on the documentation here: https://filamentphp.com/docs/3.x/tables/columns/relationships#aggregating-relationships, this should sum the total amount of quantity_in_stock for all locations. However, what I’m getting is a list of values instead. Any pointers on what I might be doing wrong? I have made sure the inventory values are casted to Integers and Floats, updated filament, cleared all caches.
Solution:
changing it to quantity_in_stock_sum made the column blank. But changing it to quantity_in_stock has it properly summing the values. Thanks for your help!
Jump to solution
7 Replies
karpadiem
karpadiemOP4mo ago
Forgot to attach the screen shot of the output!
No description
Dennis Koch
Dennis Koch4mo ago
I think the column name should be quality_in_stock_sum. They follow laravels naming schema.
Solution
karpadiem
karpadiem4mo ago
changing it to quantity_in_stock_sum made the column blank. But changing it to quantity_in_stock has it properly summing the values. Thanks for your help!
karpadiem
karpadiemOP4mo ago
@Dennis Koch I’m definitely reading in the documentation that your suggestion should be correct. I guess I’m worried something else is wrong since dropping the “_sum” made it work. Trying it three different ways,
//No Aggregating
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock'),
//documentation way
Tables\Columns\TextColumn::make('quantity_in_stock_sum')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
// working solution
Tables\Columns\TextColumn::make('quantity_in_stock')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
//No Aggregating
Tables\Columns\TextColumn::make('locationInventory.quantity_in_stock')
->label('In Stock'),
//documentation way
Tables\Columns\TextColumn::make('quantity_in_stock_sum')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
// working solution
Tables\Columns\TextColumn::make('quantity_in_stock')
->label('In Stock')
->sum('locationInventory', 'quantity_in_stock'),
karpadiem
karpadiemOP4mo ago
No description
Dennis Koch
Dennis Koch4mo ago
Probably because you pass the second param manually. As long as it works all good right?
khairulazmi_
khairulazmi_2mo ago
What did you change ? I still getting list .
Want results from more Discord servers?
Add your server