diff --git a/app/Domains/Tenant/Models/WebsiteType.php b/app/Domains/Tenant/Models/WebsiteType.php index 77d8e70..e5f877c 100644 --- a/app/Domains/Tenant/Models/WebsiteType.php +++ b/app/Domains/Tenant/Models/WebsiteType.php @@ -22,7 +22,7 @@ class WebsiteType extends Model */ public function extras(): HasMany { - return $this->hasMany(WebsiteTypeExtra::class, 'website_type'); + return $this->hasMany(WebsiteTypeExtra::class, 'website_type_code', 'codigo'); } /** diff --git a/app/Domains/Tenant/Models/WebsiteTypeExtra.php b/app/Domains/Tenant/Models/WebsiteTypeExtra.php index f3b5ffb..cdcd09b 100644 --- a/app/Domains/Tenant/Models/WebsiteTypeExtra.php +++ b/app/Domains/Tenant/Models/WebsiteTypeExtra.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; #[Fillable([ - 'website_type', + 'website_type_code', 'nombre', 'descripcion', 'is_required', @@ -27,7 +27,6 @@ class WebsiteTypeExtra extends Model protected function casts(): array { return [ - 'website_type' => 'integer', 'is_required' => 'boolean', 'config_schema' => 'array', ]; @@ -38,7 +37,7 @@ class WebsiteTypeExtra extends Model */ public function websiteType(): BelongsTo { - return $this->belongsTo(WebsiteType::class, 'website_type'); + return $this->belongsTo(WebsiteType::class, 'website_type_code', 'codigo'); } /** diff --git a/database/migrations/2026_07_29_000200_create_website_extras_tables.php b/database/migrations/2026_07_29_000200_create_website_extras_tables.php index ec02cc0..8753fb8 100644 --- a/database/migrations/2026_07_29_000200_create_website_extras_tables.php +++ b/database/migrations/2026_07_29_000200_create_website_extras_tables.php @@ -27,8 +27,10 @@ return new class extends Migration Schema::create('website_type_extras', function (Blueprint $table): void { $table->id(); - $table->foreignId('website_type') - ->constrained('website_type') + $table->string('website_type_code'); + $table->foreign('website_type_code') + ->references('codigo') + ->on('website_type') ->cascadeOnUpdate() ->cascadeOnDelete(); $table->string('nombre'); diff --git a/tests/Feature/Tenant/WebsiteExtrasTest.php b/tests/Feature/Tenant/WebsiteExtrasTest.php index 086fce3..efae4df 100644 --- a/tests/Feature/Tenant/WebsiteExtrasTest.php +++ b/tests/Feature/Tenant/WebsiteExtrasTest.php @@ -26,7 +26,7 @@ class WebsiteExtrasTest extends TestCase $this->assertEqualsCanonicalizing([ 'id', - 'website_type', + 'website_type_code', 'nombre', 'descripcion', 'is_required', @@ -68,6 +68,7 @@ class WebsiteExtrasTest extends TestCase ]); $this->assertTrue($type->extras()->firstOrFail()->is($typeExtra)); + $this->assertSame($type->codigo, $typeExtra->website_type_code); $this->assertTrue($type->tenants()->firstOrFail()->is($tenant)); $this->assertTrue($tenant->websiteType()->firstOrFail()->is($type)); $this->assertSame($type->codigo, $tenant->website_type_code);