Summing TextColumn on nested relationship

I have a GroupOrderResource that has many UserOrder, with the relationship userOrders, then my UserOrder model has this relationship with ProductSku:
public function productSkus()
  {
    return $this->belongsToMany(ProductSku::class, 'product_sku_user_order')
      ->withPivot('quantity', 'price', 'product_name', 'product_variation', 'servings') 
      ->withTrashed()
      ->withTimestamps()
      ->as('userOrderItem');
  }

Then I want my TextColumn to show all ProductSku quantities for each Group Order, and my attempt was to do this:
TextColumn::make('userOrders.productSkus_sum_quantity')
  ->sum('userOrders.productSkus', 'quantity'),

But I get this error:
Call to undefined method App\Models\GroupOrder::userOrders.productSkus()


Is this an issue with attempting to sum a number from a nested relationship, or am I doing something else wrong?
Solution
After some tinkering, I managed to do what I wanted like this:
TextColumn::make('userOrders.userOrderItems.quantity')
  ->label('Items')
  ->formatStateUsing(function ($state) {
    $quantities = explode(', ', $state);
    $totalQuantity = array_sum(array_map('intval', $quantities));
    return $totalQuantity;
  })
  ->summarize(Sum::make()),
image.png
Was this page helpful?