repository = $repository; } /** * Update a specific egg variable. * * @param int|\Pterodactyl\Models\EggVariable $variable * @param array $data * @return mixed * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException */ public function handle($variable, array $data) { if (! $variable instanceof EggVariable) { $variable = $this->repository->find($variable); } if (! is_null(array_get($data, 'env_variable'))) { if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) { throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', [ 'name' => array_get($data, 'env_variable'), ])); } $search = $this->repository->setColumns('id')->findCountWhere([ ['env_variable', '=', array_get($data, 'env_variable')], ['egg_id', '=', $variable->egg_id], ['id', '!=', $variable->id], ]); if ($search > 0) { throw new DisplayException(trans('exceptions.service.variables.env_not_unique', [ 'name' => array_get($data, 'env_variable'), ])); } } $options = array_get($data, 'options') ?? []; return $this->repository->withoutFreshModel()->update($variable->id, array_merge($data, [ 'user_viewable' => in_array('user_viewable', $options), 'user_editable' => in_array('user_editable', $options), ])); } }