service = $service; $this->repository = $repository; } /** * Updates a single variable for a server. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRequest $request * @param \Pterodactyl\Models\Server $server * @return array * * @throws \Illuminate\Validation\ValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function update(UpdateStartupVariableRequest $request, Server $server) { /** @var \Pterodactyl\Models\EggVariable $variable */ $variable = $server->variables()->where('env_variable', $request->input('key'))->first(); if (is_null($variable) || !$variable->user_viewable) { throw new BadRequestHttpException( "The environment variable you are trying to edit does not exist." ); } else if (! $variable->user_editable) { throw new BadRequestHttpException( "The environment variable you are trying to edit is read-only." ); } // Revalidate the variable value using the egg variable specific validation rules for it. $this->validate($request, ['value' => $variable->rules]); $this->repository->updateOrCreate([ 'server_id' => $server->id, 'variable_id' => $variable->id, ], [ 'variable_value' => $request->input('value'), ]); $variable = $variable->refresh(); $variable->server_value = $request->input('value'); return $this->fractal->item($variable) ->transformWith($this->getTransformer(EggVariableTransformer::class)) ->toArray(); } }