From a1aeb88061f1902d89b6f1cde4bbcc8bb3696a43 Mon Sep 17 00:00:00 2001 From: baodev0 Date: Thu, 1 Oct 2026 10:05:45 +0700 Subject: [PATCH] fix service cant show --- app/Models/Service.php | 9 ++++++++ ...26_10_01_000001_backfill_services_type.php | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 database/migrations/2026_10_01_000001_backfill_services_type.php diff --git a/app/Models/Service.php b/app/Models/Service.php index ca96678..d0af7bd 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -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 = [ diff --git a/database/migrations/2026_10_01_000001_backfill_services_type.php b/database/migrations/2026_10_01_000001_backfill_services_type.php new file mode 100644 index 0000000..301075b --- /dev/null +++ b/database/migrations/2026_10_01_000001_backfill_services_type.php @@ -0,0 +1,21 @@ +