From 89b4793667c096416dbd0b31fada472d815db2b7 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 26 Mar 2026 10:20:07 +0700 Subject: [PATCH] fix: Update MigrateNewsCommand to filter empty tags and make slug column nullable in tag migration --- app/Console/Commands/MigrateNewsCommand.php | 3 +-- database/migrations/2025_12_12_085015_create_tag_tables.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/MigrateNewsCommand.php b/app/Console/Commands/MigrateNewsCommand.php index d8f4a87..60d55a3 100644 --- a/app/Console/Commands/MigrateNewsCommand.php +++ b/app/Console/Commands/MigrateNewsCommand.php @@ -46,7 +46,6 @@ public function handle() // Get a default author ID (prefer Developer or Admin) $defaultAuthorId = DB::table('users')->first()?->id ?? 1; - $this->withProgressBar($legacyNews, function ($legacy) use ($defaultAuthorId) { // Use updateOrInsert for the basic record DB::table('news')->updateOrInsert( @@ -73,7 +72,7 @@ public function handle() if ($news) { // split by comma or other delimiter if multiple tags, // legacy 'tag' column is varchar(20), likely a single tag or comma separated - $tags = array_map('trim', explode(',', $legacy->tag)); + $tags = array_filter(array_map('trim', explode(',', $legacy->tag))); $news->syncTags($tags); } } diff --git a/database/migrations/2025_12_12_085015_create_tag_tables.php b/database/migrations/2025_12_12_085015_create_tag_tables.php index 5925c6c..5e21a2d 100644 --- a/database/migrations/2025_12_12_085015_create_tag_tables.php +++ b/database/migrations/2025_12_12_085015_create_tag_tables.php @@ -12,7 +12,7 @@ public function up(): void $table->id(); $table->json('name'); - $table->json('slug'); + $table->json('slug')->nullable(); $table->string('type')->nullable(); $table->integer('order_column')->nullable();