fix: Update MigrateNewsCommand to filter empty tags and make slug column nullable in tag migration

This commit is contained in:
Yoga Pangestu 2026-03-26 10:20:07 +07:00
parent 7d0e7c7121
commit 89b4793667
2 changed files with 2 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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();