Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Admin/Nests/EggVariableController.php
14044 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Admin\Nests;
4
5
use Illuminate\View\View;
6
use Pterodactyl\Models\Egg;
7
use Pterodactyl\Models\EggVariable;
8
use Illuminate\Http\RedirectResponse;
9
use Prologue\Alerts\AlertsMessageBag;
10
use Illuminate\View\Factory as ViewFactory;
11
use Pterodactyl\Http\Controllers\Controller;
12
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
13
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
14
use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;
15
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
16
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
17
18
class EggVariableController extends Controller
19
{
20
/**
21
* EggVariableController constructor.
22
*/
23
public function __construct(
24
protected AlertsMessageBag $alert,
25
protected VariableCreationService $creationService,
26
protected VariableUpdateService $updateService,
27
protected EggRepositoryInterface $repository,
28
protected EggVariableRepositoryInterface $variableRepository,
29
protected ViewFactory $view,
30
) {
31
}
32
33
/**
34
* Handle request to view the variables attached to an Egg.
35
*
36
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
37
*/
38
public function view(int $egg): View
39
{
40
$egg = $this->repository->getWithVariables($egg);
41
42
return view('admin.eggs.variables', ['egg' => $egg]);
43
}
44
45
/**
46
* Handle a request to create a new Egg variable.
47
*
48
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
49
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException
50
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
51
*/
52
public function store(EggVariableFormRequest $request, Egg $egg): RedirectResponse
53
{
54
$this->creationService->handle($egg->id, $request->normalize());
55
$this->alert->success(trans('admin/nests.variables.notices.variable_created'))->flash();
56
57
return redirect()->route('admin.nests.egg.variables', $egg->id);
58
}
59
60
/**
61
* Handle a request to update an existing Egg variable.
62
*
63
* @throws \Pterodactyl\Exceptions\DisplayException
64
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
65
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
66
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
67
*/
68
public function update(EggVariableFormRequest $request, Egg $egg, EggVariable $variable): RedirectResponse
69
{
70
$this->updateService->handle($variable, $request->normalize());
71
$this->alert->success(trans('admin/nests.variables.notices.variable_updated', [
72
'variable' => htmlspecialchars($variable->name),
73
]))->flash();
74
75
return redirect()->route('admin.nests.egg.variables', $egg->id);
76
}
77
78
/**
79
* Handle a request to delete an existing Egg variable from the Panel.
80
*/
81
public function destroy(int $egg, EggVariable $variable): RedirectResponse
82
{
83
$this->variableRepository->delete($variable->id);
84
$this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [
85
'variable' => htmlspecialchars($variable->name),
86
]))->flash();
87
88
return redirect()->route('admin.nests.egg.variables', $egg);
89
}
90
}
91
92