parser->handle($file); return $this->connection->transaction(function () use ($parsed) { $uuid = $parsed['uuid'] ?? Uuid::uuid4()->toString(); $egg = Egg::where('uuid', $uuid)->first() ?? new Egg(); $egg = $egg->forceFill([ 'uuid' => $uuid, 'author' => Arr::get($parsed, 'author'), 'copy_script_from' => null, ]); $egg = $this->parser->fillFromParsed($egg, $parsed); $egg->save(); foreach ($parsed['variables'] ?? [] as $variable) { EggVariable::query()->forceCreate(array_merge($variable, ['egg_id' => $egg->id])); } return $egg; }); } /** * Take an url and parse it into a new egg. * * @throws \App\Exceptions\Service\InvalidFileUploadException|\Throwable */ public function fromUrl(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(new UploadedFile($tmpPath, $info['basename'], 'application/json')); } }