Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Admin/Nests/NestController.php
10280 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Admin\Nests;
4
5
use Illuminate\View\View;
6
use Illuminate\Http\RedirectResponse;
7
use Prologue\Alerts\AlertsMessageBag;
8
use Illuminate\View\Factory as ViewFactory;
9
use Pterodactyl\Http\Controllers\Controller;
10
use Pterodactyl\Services\Nests\NestUpdateService;
11
use Pterodactyl\Services\Nests\NestCreationService;
12
use Pterodactyl\Services\Nests\NestDeletionService;
13
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
14
use Pterodactyl\Http\Requests\Admin\Nest\StoreNestFormRequest;
15
16
class NestController extends Controller
17
{
18
/**
19
* NestController constructor.
20
*/
21
public function __construct(
22
protected AlertsMessageBag $alert,
23
protected NestCreationService $nestCreationService,
24
protected NestDeletionService $nestDeletionService,
25
protected NestRepositoryInterface $repository,
26
protected NestUpdateService $nestUpdateService,
27
protected ViewFactory $view,
28
) {
29
}
30
31
/**
32
* Render nest listing page.
33
*
34
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
35
*/
36
public function index(): View
37
{
38
return view('admin.nests.index', [
39
'nests' => $this->repository->getWithCounts(),
40
]);
41
}
42
43
/**
44
* Render nest creation page.
45
*/
46
public function create(): View
47
{
48
return view('admin.nests.new');
49
}
50
51
/**
52
* Handle the storage of a new nest.
53
*
54
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
55
*/
56
public function store(StoreNestFormRequest $request): RedirectResponse
57
{
58
$nest = $this->nestCreationService->handle($request->normalize());
59
$this->alert->success(trans('admin/nests.notices.created', ['name' => htmlspecialchars($nest->name)]))->flash();
60
61
return redirect()->route('admin.nests.view', $nest->id);
62
}
63
64
/**
65
* Return details about a nest including all the eggs and servers per egg.
66
*
67
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
68
*/
69
public function view(int $nest): View
70
{
71
return view('admin.nests.view', [
72
'nest' => $this->repository->getWithEggServers($nest),
73
]);
74
}
75
76
/**
77
* Handle request to update a nest.
78
*
79
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
80
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
81
*/
82
public function update(StoreNestFormRequest $request, int $nest): RedirectResponse
83
{
84
$this->nestUpdateService->handle($nest, $request->normalize());
85
$this->alert->success(trans('admin/nests.notices.updated'))->flash();
86
87
return redirect()->route('admin.nests.view', $nest);
88
}
89
90
/**
91
* Handle request to delete a nest.
92
*
93
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
94
*/
95
public function destroy(int $nest): RedirectResponse
96
{
97
$this->nestDeletionService->handle($nest);
98
$this->alert->success(trans('admin/nests.notices.deleted'))->flash();
99
100
return redirect()->route('admin.nests');
101
}
102
}
103
104