29 lines
955 B
PHP
29 lines
955 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateVmRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('update', $this->route('vm'));
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['sometimes', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
|
'cpu' => ['sometimes', 'integer', 'min:1', 'max:32'],
|
|
'ram' => ['sometimes', 'integer', 'min:512', 'max:131072'],
|
|
'disk' => ['sometimes', 'integer', 'min:10', 'max:2048'],
|
|
'devices' => ['nullable', 'array'],
|
|
'devices.*.type' => ['required_with:devices', Rule::in(array_keys(\App\Models\VmDevice::typesFor($this->user())))],
|
|
'devices.*.slot' => ['nullable', 'string', 'max:32'],
|
|
'devices.*.config' => ['nullable', 'array'],
|
|
];
|
|
}
|
|
}
|