Summarize Sum (quantity * price)

I have an attribute in the Cart model and I want to display the sum of this column. How can I do that using the sum method in Laravel?
3 Replies
vermelen37
vermelen377mo ago
Not working, i need to get sum of Attribute filed not stored in db
Marco Mapelli
Marco Mapelli7mo ago
Placeholder::make('Cliente')
->hiddenLabel()
->content(function (OrdineTestata $record) {
$testo_html = '';
$righi = $record->righiordine;
$righiok = $righi->sum(function ($righi) {
return $righi->quantity * $righi->price;
});
$testo_html .= '<div><strong>Total: </strong>'.number_format($righiok, 2, ',', '.').' €</div>';
return new HtmlString($testo_html);
})
->columnSpan(1),
])
->columnSpan(1)
->columns(2),
Placeholder::make('Cliente')
->hiddenLabel()
->content(function (OrdineTestata $record) {
$testo_html = '';
$righi = $record->righiordine;
$righiok = $righi->sum(function ($righi) {
return $righi->quantity * $righi->price;
});
$testo_html .= '<div><strong>Total: </strong>'.number_format($righiok, 2, ',', '.').' €</div>';
return new HtmlString($testo_html);
})
->columnSpan(1),
])
->columnSpan(1)
->columns(2),