I'm trying to use sum()
get the sum of column value, but unfortunately it isn't working and I can't figure out where I am wrong.
$total = Invoice::where('status', 'Completed')
->sum('amount');
This returns error Call to a member function first() on string
invoices (Table)
id | code | status | amount |
---|---|---|---|
1 | 000001 | Completed | 300.00 |
2 | 000002 | Completed | 500.00 |
3 | 000003 | Pending | 100.00 |
I want to display the sum of invoices' amount in the view.
Blade View
Activity | Count | Total Amount |
---|---|---|
Invoices | 6 | 900.00 |