misc_pterodactyl-panel/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php

56 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Pterodactyl\Http\Requests\Api\Application\Servers;
2022-12-15 00:05:46 +00:00
use Illuminate\Support\Arr;
use Pterodactyl\Models\Server;
class UpdateServerDetailsRequest extends ServerWriteRequest
{
/**
* Rules to apply to a server details update request.
*/
public function rules(): array
{
2022-12-15 00:05:46 +00:00
$rules = Server::getRulesForUpdate($this->route()->parameter('server')->id);
return [
'external_id' => $rules['external_id'],
'name' => $rules['name'],
'user' => $rules['owner_id'],
'description' => array_merge(['nullable'], $rules['description']),
];
}
/**
* Convert the posted data into the correct format that is expected
* by the application.
2022-12-15 00:05:46 +00:00
*
* @param string|null $key
* @param string|array|null $default
*/
2022-12-15 00:05:46 +00:00
public function validated($key = null, $default = null)
{
2022-12-15 00:05:46 +00:00
$data = [
'external_id' => $this->input('external_id'),
'name' => $this->input('name'),
'owner_id' => $this->input('user'),
'description' => $this->input('description'),
];
2022-12-15 00:05:46 +00:00
return is_null($key) ? $data : Arr::get($data, $key, $default);
}
/**
2022-12-15 00:05:46 +00:00
* Rename some of the attributes in error messages to clarify the field
* being discussed.
*/
public function attributes(): array
{
return [
'user' => 'User ID',
'name' => 'Server Name',
];
}
}