input('dominio'); $hasExplicitBasePath = $this->has('base_path'); $rawBasePath = $hasExplicitBasePath ? $this->input('base_path') : TenantDomainNormalizer::pathFromDomain($rawDomain); $normalizedDomain = TenantDomainNormalizer::normalize($rawDomain); $normalizedBasePath = TenantDomainNormalizer::normalizePath($rawBasePath); $this->hasInvalidDomain = TenantDomainNormalizer::hasValue($rawDomain) && $normalizedDomain === null; $this->hasInvalidBasePath = ($hasExplicitBasePath && ! is_string($rawBasePath)) || $normalizedBasePath === null; $this->merge([ 'dominio' => $normalizedDomain, 'base_path' => $normalizedBasePath, ]); } /** * @return array */ public function rules(): array { $logoRule = ['required', new ImageOrBase64Rule]; return array_merge([ 'client_id' => ['sometimes', 'integer', Rule::exists('clients', 'id')], 'codigo' => ['required', 'string', 'max:255', Rule::unique('tenants', 'codigo')], 'nombre' => ['required', 'string', 'max:255'], 'dominio' => [ 'bail', function (string $attribute, mixed $value, Closure $fail): void { if ($this->hasInvalidDomain) { $fail("The {$attribute} field must contain a valid domain or URL."); } }, 'required', 'string', 'max:255', Rule::unique('tenants', 'dominio') ->where('base_path', $this->input('base_path')), ], 'base_path' => [ 'bail', function (string $attribute, mixed $value, Closure $fail): void { if ($this->hasInvalidBasePath) { $fail("The {$attribute} field must contain a valid URL path."); } }, 'required', 'string', 'max:255', Rule::unique('tenants', 'base_path') ->where('dominio', $this->input('dominio')), ], 'site_title' => ['sometimes', 'nullable', 'string', 'max:255'], 'primary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'secondary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'danger_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'success_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'header_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'], 'header_logo' => $logoRule, 'footer_logo' => $logoRule, 'favicon' => ['sometimes', 'nullable', new ImageOrBase64Rule], 'header_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], 'footer_bg_image' => ['sometimes', 'nullable', new ImageOrBase64Rule], 'social_media' => ['sometimes', 'array'], 'social_media.*.code' => [ 'required', 'string', 'distinct', Rule::exists('social_media', 'code'), ], 'social_media.*.url' => ['required', 'url', 'max:2048'], 'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'], 'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)], 'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)], 'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'], 'display_categories' => ['sometimes', 'boolean'], 'display_seach_bar' => ['sometimes', 'boolean'], 'display_cart' => ['sometimes', 'boolean'], 'cart_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)], 'display_cart_item_images' => ['sometimes', 'boolean'], 'scanner_category_validation_enabled' => ['sometimes', 'boolean'], 'website_type_code' => [ 'required_with:extras', 'sometimes', 'string', Rule::exists('website_type', 'codigo'), ], ], app(WebsiteExtraService::class)->requestRules($this->input('website_type_code'))); } }