first(); $championAttributes = [ 'champion_id' => $champion['id'], 'key' => $champion['key'], 'name' => $champion['name'], 'title' => $champion['title'], 'lore' => $champion['lore'], 'roles' => $champion['roles'], 'price_be' => $champion['price']['blueEssence'], 'price_rp' => $champion['price']['rp'], 'resource_type' => $champion['resource'], 'attack_type' => $champion['attackType'], 'adaptive_type' => $champion['adaptiveType'], 'release_date' => $champion['releaseDate'], 'release_patch' => $champion['releasePatch'], ]; // 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 ($championExists && $this->hasAttributesChanged($championExists, $championAttributes)) { Log::info('Champion '.$champion['name'].' has changed, updating...'); $championExists->update($championAttributes); $changeCount++; } elseif (! $championExists) { Log::info('New champion detected! Creating '.$champion['name'].'...'); Champion::create($championAttributes); $changeCount++; } } if ($changeCount > 0) { Artisan::call('cloudflare:purge'); } } private function hasAttributesChanged($champion, $attributes) { foreach ($attributes as $key => $value) { if ($champion->{$key} != $value) { return true; } } return false; } }