initial commit
This commit is contained in:
42
app/Http/Requests/StoreCustomerRequest.php
Normal file
42
app/Http/Requests/StoreCustomerRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user