environment) as $variable) { foreach ($variable as $key => $value) { $array[$key] = $value; } } return $array; } public static function syncEggs() { Nest::all()->each(function (Nest $nest) { $eggs = Pterodactyl::getEggs($nest); foreach ($eggs as $egg) { $array = []; $environment = []; $array['id'] = $egg['attributes']['id']; $array['nest_id'] = $egg['attributes']['nest']; $array['name'] = $egg['attributes']['name']; $array['description'] = $egg['attributes']['description']; $array['docker_image'] = $egg['attributes']['docker_image']; $array['startup'] = $egg['attributes']['startup']; //get environment variables foreach ($egg['attributes']['relationships']['variables']['data'] as $variable) { $environment[$variable['attributes']['env_variable']] = $variable['attributes']['default_value']; } $array['environment'] = json_encode([$environment]); self::firstOrCreate(['id' => $array['id']], $array); } }); } /** * @return BelongsTo */ public function nest() { return $this->belongsTo(Nest::class, 'id', 'nest_id'); } /** * @return BelongsToMany */ public function products() { return $this->belongsToMany(Product::class); } }