Sum (quantity * price)
Hello,
Tried for hours to get a total for orders , there's something I'm doing wrong?
or trough an attribute
Tried for hours to get a total for orders , there's something I'm doing wrong?
or trough an attribute
public function items()
{
return $this->hasMany(OrderItem::class);
}
Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->sum(\DB::raw('quantity * price'))) public function getTotalAttribute()
{
return $this->quantity * $this->price;
}
Forms\Components\Placeholder::make('total')
->content(fn ($record) => $record->items->total)