chunkById(500, function ($competitions) { foreach ($competitions as $competition) { $this->syncSeason($competition->competition_id); } }); } public function syncSeason($competitionId) { /** @var AlStatService $alStatService */ $alStatService = app(AlStatService::class); $seasons = $alStatService->getLqSeason($competitionId); if (!$seasons) { return; } foreach ($seasons as $item) { $season = JclqSeason::where('season_id', $item['id'])->first(); if (!$season) { $season = new JclqSeason(); } $season->season_id = $item['id']; $season->competition_id = intval(Arr::get($item, 'competitionId')); $season->season = strval(Arr::get($item, 'season')); $season->start_date = strval( Arr::get($item, 'startDate')); $season->end_date = strval(Arr::get($item, 'endDate')); $season->save(); } } }