fix service cant show

This commit is contained in:
baodev0
2026-10-01 10:05:45 +07:00
parent 37417cb5e0
commit a1aeb88061
2 changed files with 30 additions and 0 deletions
+9
View File
@@ -17,6 +17,15 @@ class Service extends Model
return ['uuid'];
}
protected static function booted(): void
{
static::saving(function (Service $service) {
if ($service->type === null && $service->product_id) {
$service->type = Product::query()->where('id', $service->product_id)->value('product_type');
}
});
}
protected $table = 'services';
public const HOSTING_ACCOUNT_RELATIONS = [
@@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
DB::statement(<<<'SQL'
UPDATE services
JOIN products ON products.id = services.product_id
SET services.type = products.product_type
WHERE services.type IS NULL
SQL);
}
public function down(): void
{
}
};