43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreCustomerRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$baseDomain = config('hosting.plesk.base_domain');
|
|
|
|
return [
|
|
'name' => ['required', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
|
'subdomain' => [
|
|
'required',
|
|
'string',
|
|
'max:63',
|
|
'regex:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/',
|
|
function (string $attribute, mixed $value, \Closure $fail) use ($baseDomain): void {
|
|
$domain = strtolower((string) $value).'.'.$baseDomain;
|
|
if (\App\Models\Customer::query()->where('domain', $domain)->exists()) {
|
|
$fail("The domain {$domain} is already registered.");
|
|
}
|
|
},
|
|
],
|
|
'cpu' => ['sometimes', 'integer', 'min:1', 'max:32'],
|
|
'ram' => ['sometimes', 'integer', 'min:512', 'max:131072'],
|
|
'disk' => ['sometimes', 'integer', 'min:10', 'max:2048'],
|
|
];
|
|
}
|
|
|
|
public function domain(): string
|
|
{
|
|
return strtolower($this->validated('subdomain')).'.'.config('hosting.plesk.base_domain');
|
|
}
|
|
}
|