CMS article insert/update (chiangmai, where-else): store sub_category_ids as strict CSV ('15,21' not '15, 21') so FIND_IN_SET matches every chosen sub-category, not just the first; migration strips spaces from existing rows
This commit is contained in:
1 parent
fdb71d61c7
commit
e95006a9e9
3 files changed
+26
-4
No files matched your search
+2
-2
@@ -119,7 +119,7 @@ class ArticleController extends Controller
|
||||
// prepared data
|
||||
$data = [
|
||||
'category_id' => 1,
|
||||
'sub_category_ids' => implode(", ", $sub_categories),
|
||||
'sub_category_ids' => implode(",", $sub_categories),
|
||||
'due_date' => $formattedDate,
|
||||
'name' => $name,
|
||||
'name_en' => $name_en,
|
||||
@@ -207,7 +207,7 @@ class ArticleController extends Controller
|
||||
$formattedDate = $dateObject->format('Y-m-d'); // Convert to YYYY-MM-DD
|
||||
$data = [
|
||||
'category_id' => 1,
|
||||
'sub_category_ids' => implode(", ", $sub_categories),
|
||||
'sub_category_ids' => implode(",", $sub_categories),
|
||||
'due_date' => $formattedDate,
|
||||
'active' => $active,
|
||||
'name' => $name,
|
||||
|
||||
+2
-2
@@ -118,7 +118,7 @@ class ArticleWhereElseController extends Controller
|
||||
// prepared data
|
||||
$data = [
|
||||
'category_id' => 2,
|
||||
'sub_category_ids' => implode(", ", $sub_categories),
|
||||
'sub_category_ids' => implode(",", $sub_categories),
|
||||
'due_date' => $formattedDate,
|
||||
'name' => $name,
|
||||
'name_en' => $name_en,
|
||||
@@ -206,7 +206,7 @@ class ArticleWhereElseController extends Controller
|
||||
$formattedDate = $dateObject->format('Y-m-d'); // Convert to YYYY-MM-DD
|
||||
$data = [
|
||||
'category_id' => 2,
|
||||
'sub_category_ids' => implode(", ", $sub_categories),
|
||||
'sub_category_ids' => implode(",", $sub_categories),
|
||||
'due_date' => $formattedDate,
|
||||
'active' => $active,
|
||||
'name' => $name,
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
// Article insert/update used to store sub_category_ids as "15, 21" (comma+space).
|
||||
// Every reader uses FIND_IN_SET(?, sub_category_ids), which never matches " 21",
|
||||
// so only the first checked sub-category was ever visible. Strip the spaces.
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('article')
|
||||
->where('sub_category_ids', 'like', '% %')
|
||||
->update(['sub_category_ids' => DB::raw("REPLACE(sub_category_ids, ' ', '')")]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Irreversible by design: the spaced format was a bug, not a schema.
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user