=>'sell', 'coin' => $coin])->sum('amount');
$total_buy_summ = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'buy', 'coin' => $coin])->sum('amount');
$total_sell_rate = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'sell', 'coin' => $coin, 'rate_coin' => $rate_coin])->sum('rate');
$total_buy_rate = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'buy', 'coin' => $coin, 'rate_coin' => $rate_coin])->sum('rate');
$total_sell_rate_count = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'sell', 'coin' => $coin, 'rate_coin' => $rate_coin])->count();
$total_buy_rate_count = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'buy', 'coin' => $coin, 'rate_coin' => $rate_coin])->count();
$total_offers = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where('coin', $coin)->count('id');
$total_sell_count = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'sell', 'coin' => $coin])->count();
$total_buy_count = Offers::where('expire_at', '>=', date('Y-m-d H:i:s', time()))->where(['type' =>'buy', 'coin' => $coin])->count();
$sell_average = $total_sell_rate / $total_sell_rate_count;
$buy_average = $total_buy_rate / $total_buy_rate_count;
`
как минимум можно склонировать запрос перед выборкой, что бы 2 раза не писать
опять биткоины какие -то... всё дублирующееся засунь в scope
пары count() можно заменить на один запрос groupBy по type
Обсуждают сегодня