misc_pterodactyl-panel/app/Http/Requests/Admin/ServerFormRequest.php

68 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +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
*/
namespace Pterodactyl\Http\Requests\Admin;
use Pterodactyl\Models\Server;
2017-08-05 22:26:30 +00:00
use Illuminate\Validation\Rule;
class ServerFormRequest extends AdminFormRequest
{
/**
* Rules to be applied to this request.
*
* @return array
*/
public function rules()
{
$rules = Server::getRules();
2018-01-06 18:58:30 +00:00
$rules['description'][] = 'nullable';
return $rules;
}
/**
* 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);
});
});
}
}