first(); $iconAttributes = [ 'icon_id' => $icon['id'], 'title' => $icon['title'], 'description' => $icon['descriptions'][0]['description'] ?? null, 'release_year' => $icon['yearReleased'], 'legacy' => $icon['isLegacy'], 'image' => 'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/profile-icons/'.$icon['id'].'.jpg', 'esports_team' => $icon['esportsTeam'] ?? null, 'esports_region' => $icon['esportsRegion'] ?? null, 'esports_event' => $icon['esportsEvent'] ?? null, ]; // Check if the champion already exists and if any attributes have changed, if so update the champion. If the champion doesn't exist, create it. // This is to prevent the champion data from being updated every time the seeder is run. As I'll probably run this on a cron job. if ($iconExists && $this->hasAttributesChanged($iconExists, $iconAttributes)) { Log::info('Icon '.$iconId.' has changed, updating...'); $iconExists->update($iconAttributes); $changeCount++; } elseif (! $iconExists) { Log::info('New icon detected! Creating '.$iconId.'...'); SummonerIcon::create($iconAttributes); $changeCount++; } } if ($changeCount > 0) { Artisan::call('cloudflare:purge'); } } private function hasAttributesChanged($champion, $attributes): bool { foreach ($attributes as $key => $value) { if ($champion->{$key} != $value) { return true; } } return false; } }