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 @@ +