alert = $alert; $this->creationService = $creationService; $this->databaseRepository = $databaseRepository; $this->deletionService = $deletionService; $this->repository = $repository; $this->locationRepository = $locationRepository; $this->updateService = $updateService; } /** * Display database host index. * * @return \Illuminate\View\View */ public function index(): View { return view('admin.databases.index', [ 'locations' => $this->locationRepository->getAllWithNodes(), 'hosts' => $this->repository->getWithViewDetails(), ]); } /** * Display database host to user. * * @param int $host * @return \Illuminate\View\View * * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function view(int $host): View { return view('admin.databases.view', [ 'locations' => $this->locationRepository->getAllWithNodes(), 'host' => $this->repository->find($host), 'databases' => $this->databaseRepository->getDatabasesForHost($host), ]); } /** * Handle request to create a new database host. * * @param \Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest $request * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function create(DatabaseHostFormRequest $request): RedirectResponse { try { $host = $this->creationService->handle($request->normalize()); } catch (PDOException $ex) { $this->alert->danger($ex->getMessage())->flash(); return redirect()->route('admin.databases'); } $this->alert->success('Successfully created a new database host on the system.')->flash(); return redirect()->route('admin.databases.view', $host->id); } /** * Handle updating database host. * * @param \Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest $request * @param \Pterodactyl\Models\DatabaseHost $host * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function update(DatabaseHostFormRequest $request, DatabaseHost $host): RedirectResponse { $redirect = redirect()->route('admin.databases.view', $host->id); try { $this->updateService->handle($host->id, $request->normalize()); $this->alert->success('Database host was updated successfully.')->flash(); } catch (PDOException $ex) { $this->alert->danger($ex->getMessage())->flash(); $redirect->withInput($request->normalize()); } return $redirect; } /** * Handle request to delete a database host. * * @param int $host * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException */ public function delete(int $host): RedirectResponse { $this->deletionService->handle($host); $this->alert->success('The requested database host has been deleted from the system.')->flash(); return redirect()->route('admin.databases'); } }