/** * @param $match_id * @return array that consists of the match, team's last 7 matches results, and head to head results */ public static function getMatchStats($match_id) { //get the match $match = DB::table('matches')->select('matches.id', 'matches.team_a', 'matches.team_b', 'matches.winner', 'matches.a_odds', 'matches.b_odds', 'matches.format', 'matches.event', 'matches.time', 'matches.result_category', 'matches.odds_tracker', 't1.logo as logo_a', 't2.logo as logo_b')->where('matches.id', $match_id)->join('teams as t1', 'matches.team_a_id', '=', 't1.id')->join('teams as t2', 'matches.team_b_id', '=', 't2.id')->first(); // team a results $a_matches = DB::table('matches')->select('id', 'team_a', 'team_b', 'winner', 'a_odds', 'b_odds', 'format', 'event', 'time', 'result_category')->where(function ($query) use($match) { $query->where('team_a', $match->team_a)->orWhere('team_b', $match->team_a); })->where('closed', '1')->where('result_category', '<>', 'NONE')->where('time', '<', $match->time)->orderBy('time', 'desc')->limit('7')->get(); //team b results $b_matches = DB::table('matches')->select('id', 'team_a', 'team_b', 'winner', 'a_odds', 'b_odds', 'format', 'time', 'result_category')->where(function ($query) use($match) { $query->where('team_a', $match->team_b)->orWhere('team_b', $match->team_b); })->where('closed', '1')->where('result_category', '<>', 'NONE')->where('time', '<', $match->time)->orderBy('time', 'desc')->limit('7')->get(); //head to head matches $head_to_head = DB::table('matches')->select('id', 'team_a', 'team_b', 'winner', 'a_odds', 'b_odds', 'format', 'time', 'result_category')->where(function ($query) use($match) { $query->where(function ($query) use($match) { $query->where('team_a', $match->team_a)->where('team_b', $match->team_b); }); $query->orWhere(function ($query) use($match) { $query->where('team_b', $match->team_a)->where('team_a', $match->team_b); }); })->where('closed', 1)->where('result_category', '<>', 'NONE')->where('time', '<', $match->time)->orderBy('time', 'desc')->limit(7)->get(); $a_matches = ApiUtils::prettifyMatches($a_matches, $match->team_a); $b_matches = ApiUtils::prettifyMatches($b_matches, $match->team_b); $head_to_head = ApiUtils::prettifyMatches($head_to_head, $match->team_a); return ['match' => $match, 'a' => $a_matches, 'b' => $b_matches, 'head_to_head' => $head_to_head]; }
public function matchStatsApi($id) { return ApiUtils::getMatchStats($id); }