chunkById(500, function($competitions) { foreach ($competitions as $competition) { $this->syncMatch($competition->competition_id, $competition->curr_season); } }); } public function syncMatch($competitionId, $season) { /** @var AlStatService $alStatService */ $alStatService = app(AlStatService::class); $matches = $alStatService->getZqMatches($competitionId, $season); if (!$matches) { return; } foreach ($matches as $item) { $matchId = $item['id']; $match = ZqMatch::withTrashed()->select('id')->where('match_id', $matchId)->first(); if (!$match) { $match = new ZqMatch(); } $match->match_id = $matchId; $match->competition_id = intval(Arr::get($item, 'competitionId')); $match->competition_name = strval(Arr::get($item, 'competitionName')); $match->season = strval(Arr::get($item, 'season')); $match->stage = strval(Arr::get($item, 'stage')); $match->group_id = intval(Arr::get($item, 'groupId')); $match->group_name = strval(Arr::get($item, 'groupName')); $match->start_time = Arr::get($item, 'startTime', null); $match->home_team_id = intval(Arr::get($item, 'homeTeamId')); $match->away_team_id = intval(Arr::get($item, 'awayTeamId')); $match->home_team_name = strval(Arr::get($item, 'homeTeamName')); $match->away_team_name = strval(Arr::get($item, 'awayTeamName')); $match->status = intval(Arr::get($item, 'status')); $match->half_time_score = strval(Arr::get($item, 'halfTimeScore')); $match->full_time_score = strval(Arr::get($item, 'fullTimeScore')); $match->extra_time_score = strval(Arr::get($item, 'extraTimeScore')); $match->penal_score = strval(Arr::get($item, 'penalScore')); $match->final_score = strval(Arr::get($item, 'finalScore')); $match->win_team_id = intval(Arr::get($item, 'winTeamId')); $match->man_id = strval(Arr::get($item, 'manId')); $match->save(); } } }