Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Admin/ServerFormRequest.php
10266 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Admin;
4
5
use Pterodactyl\Models\Server;
6
use Illuminate\Validation\Rule;
7
use Illuminate\Validation\Validator;
8
9
class ServerFormRequest extends AdminFormRequest
10
{
11
/**
12
* Rules to be applied to this request.
13
*/
14
public function rules(): array
15
{
16
$rules = Server::getRules();
17
$rules['description'][] = 'nullable';
18
$rules['custom_image'] = 'sometimes|nullable|string';
19
20
return $rules;
21
}
22
23
/**
24
* Run validation after the rules above have been applied.
25
*/
26
public function withValidator(Validator $validator): void
27
{
28
$validator->after(function ($validator) {
29
$validator->sometimes('node_id', 'required|numeric|bail|exists:nodes,id', function ($input) {
30
return !$input->auto_deploy;
31
});
32
33
$validator->sometimes('allocation_id', [
34
'required',
35
'numeric',
36
'bail',
37
Rule::exists('allocations', 'id')->where(function ($query) {
38
$query->where('node_id', $this->input('node_id'));
39
$query->whereNull('server_id');
40
}),
41
], function ($input) {
42
return !$input->auto_deploy;
43
});
44
45
$validator->sometimes('allocation_additional.*', [
46
'sometimes',
47
'required',
48
'numeric',
49
Rule::exists('allocations', 'id')->where(function ($query) {
50
$query->where('node_id', $this->input('node_id'));
51
$query->whereNull('server_id');
52
}),
53
], function ($input) {
54
return !$input->auto_deploy;
55
});
56
});
57
}
58
}
59
60