2017-07-20 01:49:41 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-07-20 01:49:41 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-20 01:49:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Admin;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Illuminate\Validation\Rule;
|
2017-07-20 01:49:41 +00:00
|
|
|
|
|
|
|
class ServerFormRequest extends AdminFormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Rules to be applied to this request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2019-09-05 05:26:28 +00:00
|
|
|
$rules = Server::getRules();
|
2018-01-06 18:58:30 +00:00
|
|
|
$rules['description'][] = 'nullable';
|
|
|
|
|
|
|
|
return $rules;
|
2017-07-20 01:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run validation after the rules above have been applied.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Validation\Validator $validator
|
|
|
|
*/
|
|
|
|
public function withValidator($validator)
|
|
|
|
{
|
|
|
|
$validator->after(function ($validator) {
|
|
|
|
$validator->sometimes('node_id', 'required|numeric|bail|exists:nodes,id', function ($input) {
|
|
|
|
return ! ($input->auto_deploy);
|
|
|
|
});
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
return ! ($input->auto_deploy);
|
|
|
|
});
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
return ! ($input->auto_deploy);
|
|
|
|
});
|
2017-07-22 02:17:42 +00:00
|
|
|
|
2017-07-25 02:34:10 +00:00
|
|
|
$validator->sometimes('pack_id', [
|
|
|
|
Rule::exists('packs', 'id')->where(function ($query) {
|
|
|
|
$query->where('selectable', 1);
|
2017-10-07 23:08:19 +00:00
|
|
|
$query->where('egg_id', $this->input('egg_id'));
|
2017-07-25 02:34:10 +00:00
|
|
|
}),
|
|
|
|
], function ($input) {
|
|
|
|
return $input->pack_id !== 0 && $input->pack_id !== null;
|
|
|
|
});
|
2017-07-20 01:49:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|