Path: blob/1.0-develop/app/Http/Controllers/Admin/Nests/EggVariableController.php
14044 views
<?php12namespace Pterodactyl\Http\Controllers\Admin\Nests;34use Illuminate\View\View;5use Pterodactyl\Models\Egg;6use Pterodactyl\Models\EggVariable;7use Illuminate\Http\RedirectResponse;8use Prologue\Alerts\AlertsMessageBag;9use Illuminate\View\Factory as ViewFactory;10use Pterodactyl\Http\Controllers\Controller;11use Pterodactyl\Contracts\Repository\EggRepositoryInterface;12use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;13use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;14use Pterodactyl\Services\Eggs\Variables\VariableCreationService;15use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;1617class EggVariableController extends Controller18{19/**20* EggVariableController constructor.21*/22public function __construct(23protected AlertsMessageBag $alert,24protected VariableCreationService $creationService,25protected VariableUpdateService $updateService,26protected EggRepositoryInterface $repository,27protected EggVariableRepositoryInterface $variableRepository,28protected ViewFactory $view,29) {30}3132/**33* Handle request to view the variables attached to an Egg.34*35* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException36*/37public function view(int $egg): View38{39$egg = $this->repository->getWithVariables($egg);4041return view('admin.eggs.variables', ['egg' => $egg]);42}4344/**45* Handle a request to create a new Egg variable.46*47* @throws \Pterodactyl\Exceptions\Model\DataValidationException48* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException49* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException50*/51public function store(EggVariableFormRequest $request, Egg $egg): RedirectResponse52{53$this->creationService->handle($egg->id, $request->normalize());54$this->alert->success(trans('admin/nests.variables.notices.variable_created'))->flash();5556return redirect()->route('admin.nests.egg.variables', $egg->id);57}5859/**60* Handle a request to update an existing Egg variable.61*62* @throws \Pterodactyl\Exceptions\DisplayException63* @throws \Pterodactyl\Exceptions\Model\DataValidationException64* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException65* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException66*/67public function update(EggVariableFormRequest $request, Egg $egg, EggVariable $variable): RedirectResponse68{69$this->updateService->handle($variable, $request->normalize());70$this->alert->success(trans('admin/nests.variables.notices.variable_updated', [71'variable' => htmlspecialchars($variable->name),72]))->flash();7374return redirect()->route('admin.nests.egg.variables', $egg->id);75}7677/**78* Handle a request to delete an existing Egg variable from the Panel.79*/80public function destroy(int $egg, EggVariable $variable): RedirectResponse81{82$this->variableRepository->delete($variable->id);83$this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [84'variable' => htmlspecialchars($variable->name),85]))->flash();8687return redirect()->route('admin.nests.egg.variables', $egg);88}89}909192