58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Whmcs;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProvisionServiceRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'whmcs_service_id' => ['required', 'integer', 'unique:whmcs_services,whmcs_service_id'],
|
|
'whmcs_client_id' => ['required', 'integer'],
|
|
'whmcs_order_id' => ['nullable', 'integer'],
|
|
'client_email' => ['required', 'email', 'max:255'],
|
|
'client_name' => ['required', 'string', 'max:100'],
|
|
'plan_slug' => ['required', 'string', 'exists:hosting_plans,slug'],
|
|
'hostname' => ['required', 'string', 'max:100', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/'],
|
|
'subdomain' => [
|
|
Rule::requiredIf(fn () => $this->boolean('behind_traefik', true)),
|
|
'nullable',
|
|
'string',
|
|
'max:63',
|
|
'regex:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/',
|
|
],
|
|
'behind_traefik' => ['boolean'],
|
|
'provision_mode' => ['required', Rule::in(['template', 'iso', 'empty'])],
|
|
'template_slug' => [
|
|
Rule::requiredIf(fn () => $this->input('provision_mode') === 'template'),
|
|
'nullable',
|
|
'string',
|
|
'max:64',
|
|
],
|
|
'iso_volid' => [
|
|
Rule::requiredIf(fn () => $this->input('provision_mode') === 'iso'),
|
|
'nullable',
|
|
'string',
|
|
'max:255',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function domain(): ?string
|
|
{
|
|
if (! $this->boolean('behind_traefik', true) || ! $this->filled('subdomain')) {
|
|
return null;
|
|
}
|
|
|
|
return strtolower($this->input('subdomain')).'.'.config('hosting.plesk.base_domain');
|
|
}
|
|
}
|