How do i calculate the totals of all values of a column amount
after fetching it in laravel controller. table collections
has only amount and id
column and i want to determine the totals.
CodePudding user response:
You can use sum
from eloquent:
$amount = Collections::sum('amount');
CodePudding user response:
You can do the following:
$total = 0;
$amounts = Collections::all()->pluck('amount');
foreach($amounts as $amount){
$total = $amount;
}