Как получить общую сумму из цикла foreach в контроллере Laravel ⇐ Php
-
Anonymous
Как получить общую сумму из цикла foreach в контроллере Laravel
I want to get total amount from foreach lop data in the controller, for example, code bellow.
$set = settings::findOrFail(1); $api = new \Binance\API("$set->api_key","$set->scrt_key"); $api->useServerTime(); $forusdvaluetotal = coins::whereuser_id(Auth::user()->id)->get(); foreach($forusdvaluetotal as $coins){ $getsymbol = $coins->symbol.'USDT'; $getprice = $api->price("$getsymbol"); $valueinusd = $coins->balance*$getprice; $total = $valueinusd; } $gettotal = $total->sum(); like "coins A" price is $50 per coin and balance 2, "coins B" price is $50 per coin and balance 5, "coins C" price is $50 per coin and balance 1. So I want to get total amount in USD by balance like ('coins A' $502 = $100 + 'coins B' $505 = $250 + 'coins A' $50*1 = $50) = $400
Please help me how to solve that in laravel controller.
Источник: https://stackoverflow.com/questions/692 ... controller
I want to get total amount from foreach lop data in the controller, for example, code bellow.
$set = settings::findOrFail(1); $api = new \Binance\API("$set->api_key","$set->scrt_key"); $api->useServerTime(); $forusdvaluetotal = coins::whereuser_id(Auth::user()->id)->get(); foreach($forusdvaluetotal as $coins){ $getsymbol = $coins->symbol.'USDT'; $getprice = $api->price("$getsymbol"); $valueinusd = $coins->balance*$getprice; $total = $valueinusd; } $gettotal = $total->sum(); like "coins A" price is $50 per coin and balance 2, "coins B" price is $50 per coin and balance 5, "coins C" price is $50 per coin and balance 1. So I want to get total amount in USD by balance like ('coins A' $502 = $100 + 'coins B' $505 = $250 + 'coins A' $50*1 = $50) = $400
Please help me how to solve that in laravel controller.
Источник: https://stackoverflow.com/questions/692 ... controller
Мобильная версия