2017-07-20 01:49:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Admin;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Validation\Validator;
|
2017-07-20 01:49:41 +00:00
|
|
|
|
|
|
|
class ServerFormRequest extends AdminFormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Rules to be applied to this request.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function rules(): array
|
2017-07-20 01:49:41 +00:00
|
|
|
{
|
2019-09-05 05:26:28 +00:00
|
|
|
$rules = Server::getRules();
|
2018-01-06 18:58:30 +00:00
|
|
|
$rules['description'][] = 'nullable';
|
2020-12-13 17:53:17 +00:00
|
|
|
$rules['custom_image'] = 'sometimes|nullable|string';
|
2018-01-06 18:58:30 +00:00
|
|
|
|
|
|
|
return $rules;
|
2017-07-20 01:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run validation after the rules above have been applied.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function withValidator(Validator $validator): void
|
2017-07-20 01:49:41 +00:00
|
|
|
{
|
|
|
|
$validator->after(function ($validator) {
|
|
|
|
$validator->sometimes('node_id', 'required|numeric|bail|exists:nodes,id', function ($input) {
|
2022-10-14 16:59:20 +00:00
|
|
|
return !$input->auto_deploy;
|
2017-07-20 01:49:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$validator->sometimes('allocation_id', [
|
|
|
|
'required',
|
|
|
|
'numeric',
|
|
|
|
'bail',
|
|
|
|
Rule::exists('allocations', 'id')->where(function ($query) {
|
|
|
|
$query->where('node_id', $this->input('node_id'));
|
|
|
|
$query->whereNull('server_id');
|
|
|
|
}),
|
|
|
|
], function ($input) {
|
2022-10-14 16:59:20 +00:00
|
|
|
return !$input->auto_deploy;
|
2017-07-20 01:49:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$validator->sometimes('allocation_additional.*', [
|
|
|
|
'sometimes',
|
|
|
|
'required',
|
|
|
|
'numeric',
|
|
|
|
Rule::exists('allocations', 'id')->where(function ($query) {
|
|
|
|
$query->where('node_id', $this->input('node_id'));
|
|
|
|
$query->whereNull('server_id');
|
|
|
|
}),
|
|
|
|
], function ($input) {
|
2022-10-14 16:59:20 +00:00
|
|
|
return !$input->auto_deploy;
|
2017-07-20 01:49:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|