diff --git a/app/Domains/Tenant/Services/WebsiteExtraService.php b/app/Domains/Tenant/Services/WebsiteExtraService.php index 4d4f3c5..6f15229 100644 --- a/app/Domains/Tenant/Services/WebsiteExtraService.php +++ b/app/Domains/Tenant/Services/WebsiteExtraService.php @@ -12,7 +12,6 @@ use App\Domains\Tenant\Models\WebsiteType; use App\Domains\Tenant\Models\WebsiteTypeExtra; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; use InvalidArgumentException; @@ -115,8 +114,6 @@ class WebsiteExtraService $config, $requestRoot ); - $this->validateDatabaseConfig($definition, $transformedConfig, $requestRoot); - $tenant->websiteExtras()->create([ 'website_type_extra_id' => $definition->id, 'config' => $transformedConfig, @@ -161,7 +158,6 @@ class WebsiteExtraService return DB::transaction(function () use ($tenant, $definition, $config): WebsiteExtra { $transformedConfig = $this->applyTransforms($tenant, $definition, $config, 'config'); - $this->validateDatabaseConfig($definition, $transformedConfig, 'config'); return $tenant->websiteExtras()->updateOrCreate( ['website_type_extra_id' => $definition->id], @@ -342,33 +338,4 @@ class WebsiteExtraService return $attachment->id; } - - private function validateDatabaseConfig( - WebsiteTypeExtra $definition, - mixed $config, - string $requestRoot - ): void { - $schemaRules = $definition->config_schema['database_rules'] ?? []; - $rules = []; - - foreach ($schemaRules as $path => $pathRules) { - $attribute = $path === '$' - ? 'config' - : 'config.'.ltrim(str_starts_with($path, '$.') ? substr($path, 2) : $path, '.'); - $rules[$attribute] = $this->compileRules($pathRules); - } - - $validator = Validator::make(['config' => $config], $rules); - - if ($validator->fails()) { - $messages = []; - - foreach ($validator->errors()->toArray() as $attribute => $errors) { - $suffix = $attribute === 'config' ? '' : substr($attribute, strlen('config')); - $messages["{$requestRoot}{$suffix}"] = $errors; - } - - throw ValidationException::withMessages($messages); - } - } } diff --git a/database/migrations/2026_07_31_000300_remove_database_rules_from_website_type_extras.php b/database/migrations/2026_07_31_000300_remove_database_rules_from_website_type_extras.php new file mode 100644 index 0000000..6ec98ff --- /dev/null +++ b/database/migrations/2026_07_31_000300_remove_database_rules_from_website_type_extras.php @@ -0,0 +1,32 @@ +select(['id', 'config_schema']) + ->orderBy('id') + ->each(function (object $definition): void { + $schema = json_decode($definition->config_schema, true); + + if (! is_array($schema) || ! array_key_exists('database_rules', $schema)) { + return; + } + + unset($schema['database_rules']); + + DB::table('website_type_extras') + ->where('id', $definition->id) + ->update(['config_schema' => json_encode($schema)]); + }); + } + + public function down(): void + { + // Removed rules cannot be reconstructed generically. + } +}; diff --git a/database/seeders/WebsiteTypeSeeder.php b/database/seeders/WebsiteTypeSeeder.php index 217edfe..489446c 100644 --- a/database/seeders/WebsiteTypeSeeder.php +++ b/database/seeders/WebsiteTypeSeeder.php @@ -31,10 +31,6 @@ class WebsiteTypeSeeder extends Seeder 'attachment_type' => 'image', ], ], - 'database_rules' => [ - '$' => 'required|array', - '$.*' => 'required|integer|distinct|exists:attachments,id', - ], ], ], ); @@ -65,14 +61,6 @@ class WebsiteTypeSeeder extends Seeder 'attachment_type' => 'image', ], ], - 'database_rules' => [ - '$' => 'required|array', - 'title_html' => 'nullable|string', - 'description_html' => 'nullable|string', - 'button_text' => 'nullable|string', - 'button_href' => 'nullable|string', - 'background_image_id' => 'nullable|integer|exists:attachments,id', - ], ], ], ); @@ -93,14 +81,6 @@ class WebsiteTypeSeeder extends Seeder 'dates.*' => 'required|date_format:Y-m-d|distinct', ], 'transforms' => [], - 'database_rules' => [ - '$' => 'required|array', - 'title' => 'nullable|string', - 'location' => 'nullable|string', - 'dates_text' => 'nullable|string|max:255', - 'dates' => 'nullable|array', - 'dates.*' => 'required|date_format:Y-m-d|distinct', - ], ], ], ); diff --git a/tests/Feature/Seeders/WebsiteTypeSeederTest.php b/tests/Feature/Seeders/WebsiteTypeSeederTest.php index f009d49..2d39e9f 100644 --- a/tests/Feature/Seeders/WebsiteTypeSeederTest.php +++ b/tests/Feature/Seeders/WebsiteTypeSeederTest.php @@ -37,10 +37,6 @@ class WebsiteTypeSeederTest extends TestCase 'attachment_type' => 'image', ], ], - 'database_rules' => [ - '$' => 'required|array', - '$.*' => 'required|integer|distinct|exists:attachments,id', - ], ], $shopIt->extras->sole()->config_schema); $onTicket = WebsiteType::query() @@ -70,14 +66,6 @@ class WebsiteTypeSeederTest extends TestCase 'attachment_type' => 'image', ], ], - 'database_rules' => [ - '$' => 'required|array', - 'title_html' => 'nullable|string', - 'description_html' => 'nullable|string', - 'button_text' => 'nullable|string', - 'button_href' => 'nullable|string', - 'background_image_id' => 'nullable|integer|exists:attachments,id', - ], ], $heroSchema); $eventSchema = $onTicket->extras->firstWhere('codigo', 'eventConfig')->config_schema; @@ -91,14 +79,6 @@ class WebsiteTypeSeederTest extends TestCase 'dates.*' => 'required|date_format:Y-m-d|distinct', ], 'transforms' => [], - 'database_rules' => [ - '$' => 'required|array', - 'title' => 'nullable|string', - 'location' => 'nullable|string', - 'dates_text' => 'nullable|string|max:255', - 'dates' => 'nullable|array', - 'dates.*' => 'required|date_format:Y-m-d|distinct', - ], ], $eventSchema); } } diff --git a/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php b/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php index 57022ff..0bf3f1c 100644 --- a/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php +++ b/tests/Feature/Tenant/AdminAppWebsiteExtraControllerTest.php @@ -39,10 +39,6 @@ class AdminAppWebsiteExtraControllerTest extends TestCase 'phone' => 'required|string|max:30', ], 'transforms' => [], - 'database_rules' => [ - '$' => 'required|array', - 'phone' => 'required|string|max:30', - ], ], ]); } @@ -100,7 +96,6 @@ class AdminAppWebsiteExtraControllerTest extends TestCase 'config_schema' => [ 'request_rules' => ['$' => 'required|array'], 'transforms' => [], - 'database_rules' => ['$' => 'required|array'], ], ]);