/** * @return \Illuminate\Http\JsonResponse */ public function live() { $match = $this->matches->with(['events', 'competition', 'team_as_home', 'team_as_away'])->whereNotIn('status', ['FT', 'Postp.'])->whereDate('formatted_date', '>=', Date::yesterday()->format('Y-m-d'))->orderBy('formatted_date', 'asc')->first(); return response()->json($match); }
/** * * @return array|string|static[] */ public function LiveMatch() { $getMatchId = $this->footballMatches->whereNotIn('status', ['FT', 'Postp.'])->whereDate('formatted_date', '>=', Date::yesterday()->format('Y-m-d'))->orderBy('formatted_date', 'asc')->first(); $request = 'matches/' . $getMatchId['match_id'] . '?'; $match = $this->connector($request); $match['match_id'] = $match['id']; unset($match['id']); $mergeDateTime = Date::createFromFormat('d.m.Y H:i', $match['formatted_date'] . ' ' . $match['time'], 'UTC')->tz('Asia/Bangkok')->toDateTimeString(); $date = Date::createFromFormat('Y-m-d H:i:s', $mergeDateTime)->format('Y-m-d'); $match['formatted_date'] = $date; $time = Date::createFromFormat('Y-m-d H:i:s', $mergeDateTime)->format('H:i'); $matchStatus = $match['status']; $match['status'] === $match['time'] ? $match['status'] = $time : ($match['status'] = $matchStatus); $match['time'] = $time; if ($match['localteam_score'] === '?' and $match['visitorteam_score'] === '?' or $match['localteam_score'] === '' and $match['visitorteam_score'] === '') { if ($match['status'] !== 'FT' or $match['status'] !== 'AET') { $match['localteam_score'] = '-'; $match['visitorteam_score'] = '-'; } } $this->footballMatches->updateOrCreate(['match_id' => $match['match_id']], $match); if (!empty($match['events'])) { $matchEvents = $match['events']; $matchId = $match['match_id']; foreach ($matchEvents as $matchEvent) { $matchEvent['match_id'] = $matchId; $matchEvent['event_id'] = $matchEvent['id']; unset($matchEvent['id']); $this->footballMatchEvents->updateOrCreate(['event_id' => $matchEvent['event_id']], $matchEvent) ? Log::info('Event of ' . $matchId . ' update completed!.') : Log::error('Event update process of ' . $matchId . ' failed'); } } Event::fire(new FootballMatchUpdated($this->footballMatches)); return Log::info('All data of ' . $match['match_id'] . ' update completed!'); }