Path: blob/1.0-develop/app/Http/Controllers/Admin/Nests/NestController.php
10280 views
<?php12namespace Pterodactyl\Http\Controllers\Admin\Nests;34use Illuminate\View\View;5use Illuminate\Http\RedirectResponse;6use Prologue\Alerts\AlertsMessageBag;7use Illuminate\View\Factory as ViewFactory;8use Pterodactyl\Http\Controllers\Controller;9use Pterodactyl\Services\Nests\NestUpdateService;10use Pterodactyl\Services\Nests\NestCreationService;11use Pterodactyl\Services\Nests\NestDeletionService;12use Pterodactyl\Contracts\Repository\NestRepositoryInterface;13use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest;1415class NestController extends Controller16{17/**18* NestController constructor.19*/20public function __construct(21protected AlertsMessageBag $alert,22protected NestCreationService $nestCreationService,23protected NestDeletionService $nestDeletionService,24protected NestRepositoryInterface $repository,25protected NestUpdateService $nestUpdateService,26protected ViewFactory $view,27) {28}2930/**31* Render nest listing page.32*33* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException34*/35public function index(): View36{37return view('admin.nests.index', [38'nests' => $this->repository->getWithCounts(),39]);40}4142/**43* Render nest creation page.44*/45public function create(): View46{47return view('admin.nests.new');48}4950/**51* Handle the storage of a new nest.52*53* @throws \Pterodactyl\Exceptions\Model\DataValidationException54*/55public function store(StoreNestFormRequest $request): RedirectResponse56{57$nest = $this->nestCreationService->handle($request->normalize());58$this->alert->success(trans('admin/nests.notices.created', ['name' => htmlspecialchars($nest->name)]))->flash();5960return redirect()->route('admin.nests.view', $nest->id);61}6263/**64* Return details about a nest including all the eggs and servers per egg.65*66* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException67*/68public function view(int $nest): View69{70return view('admin.nests.view', [71'nest' => $this->repository->getWithEggServers($nest),72]);73}7475/**76* Handle request to update a nest.77*78* @throws \Pterodactyl\Exceptions\Model\DataValidationException79* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException80*/81public function update(StoreNestFormRequest $request, int $nest): RedirectResponse82{83$this->nestUpdateService->handle($nest, $request->normalize());84$this->alert->success(trans('admin/nests.notices.updated'))->flash();8586return redirect()->route('admin.nests.view', $nest);87}8889/**90* Handle request to delete a nest.91*92* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException93*/94public function destroy(int $nest): RedirectResponse95{96$this->nestDeletionService->handle($nest);97$this->alert->success(trans('admin/nests.notices.deleted'))->flash();9899return redirect()->route('admin.nests');100}101}102103104