Path: blob/1.0-develop/app/Http/Controllers/Admin/LocationController.php
10279 views
<?php12namespace Pterodactyl\Http\Controllers\Admin;34use Illuminate\View\View;5use Pterodactyl\Models\Location;6use Illuminate\Http\RedirectResponse;7use Prologue\Alerts\AlertsMessageBag;8use Illuminate\View\Factory as ViewFactory;9use Pterodactyl\Exceptions\DisplayException;10use Pterodactyl\Http\Controllers\Controller;11use Pterodactyl\Http\Requests\Admin\LocationFormRequest;12use Pterodactyl\Services\Locations\LocationUpdateService;13use Pterodactyl\Services\Locations\LocationCreationService;14use Pterodactyl\Services\Locations\LocationDeletionService;15use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;1617class LocationController extends Controller18{19/**20* LocationController constructor.21*/22public function __construct(23protected AlertsMessageBag $alert,24protected LocationCreationService $creationService,25protected LocationDeletionService $deletionService,26protected LocationRepositoryInterface $repository,27protected LocationUpdateService $updateService,28protected ViewFactory $view,29) {30}3132/**33* Return the location overview page.34*/35public function index(): View36{37return view('admin.locations.index', [38'locations' => $this->repository->getAllWithDetails(),39]);40}4142/**43* Return the location view page.44*45* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException46*/47public function view(int $id): View48{49return view('admin.locations.view', [50'location' => $this->repository->getWithNodes($id),51]);52}5354/**55* Handle request to create new location.56*57* @throws \Throwable58*/59public function create(LocationFormRequest $request): RedirectResponse60{61$location = $this->creationService->handle($request->normalize());62$this->alert->success('Location was created successfully.')->flash();6364return redirect()->route('admin.locations.view', $location->id);65}6667/**68* Handle request to update or delete location.69*70* @throws \Throwable71*/72public function update(LocationFormRequest $request, Location $location): RedirectResponse73{74if ($request->input('action') === 'delete') {75return $this->delete($location);76}7778$this->updateService->handle($location->id, $request->normalize());79$this->alert->success('Location was updated successfully.')->flash();8081return redirect()->route('admin.locations.view', $location->id);82}8384/**85* Delete a location from the system.86*87* @throws \Exception88* @throws DisplayException89*/90public function delete(Location $location): RedirectResponse91{92try {93$this->deletionService->handle($location->id);9495return redirect()->route('admin.locations');96} catch (DisplayException $ex) {97$this->alert->danger($ex->getMessage())->flash();98}99100return redirect()->route('admin.locations.view', $location->id);101}102}103104105