Sum (quantity * price)

Hello,
Tried for hours to get a total for orders , there's something I'm doing wrong?


public function items()
    {
        return $this->hasMany(OrderItem::class);
    }

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->sum(\DB::raw('quantity * price')))

or trough an attribute

  public function getTotalAttribute()
  {
    return $this->quantity * $this->price;
  }

Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->total)
Was this page helpful?