Моя 3 различных функции дали мне значение, как показано ниже: JSON
.
Я хочу ПЕЧАТЬ имени function
который имеет наибольшее значение .Функции:
public function firstHourTrades()
{
$user_id = Auth::user()->id;
$data = DB::table('finaltrade')
->select(DB::raw('count(*) as first_hour'))
->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
->where('finaltrade.user_id', $user_id)
->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '>=', DB::raw('exchanges.start_time'))
->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '<=', DB::raw("ADDTIME(exchanges.start_time, '1:00:00')"))
->get();
return response()->json($data);
}
public function lastHourTrades()
{
$user_id = Auth::user()->id;
$data = DB::table('finaltrade')
->select(DB::raw('count(*) as last_hour'))
->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
->where('finaltrade.user_id', $user_id)
->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '<=', DB::raw('exchanges.close_time'))
->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '>=', DB::raw("SUBTIME(exchanges.close_time, '01:00:00')"))
->get();
return response()->json($data);
}
public function otherHoursTrades()
{
$user_id = Auth::user()->id;
$data = DB::table('finaltrade')
->select(DB::raw('count(*) as other_hours'))
->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
->where('finaltrade.user_id', $user_id)
->whereRaw('finaltrade.created_at NOT BETWEEN exchanges.start_time AND DATE_ADD(exchanges.start_time, INTERVAL 1 HOUR)')
->whereRaw('finaltrade.created_at NOT BETWEEN exchanges.close_time AND DATE_SUB(exchanges.close_time, INTERVAL 1 HOUR)')
->get();
return response()->json($data);
}
ОТ ОТВЕТА, который Я СОЗДАЛ:
public function allCmp()
{
$func_names = ['firstHourTrades()','lastHourTrades()','otherHoursTrades()'];
foreach($func_names as $name)
$results[$name] = $name();
$max = max($results);
DD($max);
}