parser->handle($file); return $this->connection->transaction(function () use ($egg, $parsed) { $egg = $this->parser->fillFromParsed($egg, $parsed); $egg->save(); // Update existing variables or create new ones. foreach ($parsed['variables'] ?? [] as $variable) { EggVariable::unguarded(function () use ($egg, $variable) { $egg->variables()->updateOrCreate([ 'env_variable' => $variable['env_variable'], ], Collection::make($variable)->except(['egg_id', 'env_variable'])->toArray()); }); } $imported = array_map(fn ($value) => $value['env_variable'], $parsed['variables'] ?? []); $egg->variables()->whereNotIn('env_variable', $imported)->delete(); return $egg->refresh(); }); } /** * Update an existing Egg using an url. * * @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable */ public function fromUrl(Egg $egg, string $url): Egg { $info = pathinfo($url); $tmpDir = TemporaryDirectory::make()->deleteWhenDestroyed(); $tmpPath = $tmpDir->path($info['basename']); file_put_contents($tmpPath, file_get_contents($url)); return $this->fromFile($egg, new UploadedFile($tmpPath, $info['basename'], 'application/json')); } }