From 397a8a64844a827d88418599e311c76cc581bccc Mon Sep 17 00:00:00 2001 From: sky121113 Date: Thu, 5 Feb 2026 16:18:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(product):=20=E8=A8=AD=E5=AE=9A=20is=5Factiv?= =?UTF-8?q?e=20=E6=AC=84=E4=BD=8D=E9=A0=90=E8=A8=AD=E7=82=BA=20true=20?= =?UTF-8?q?=E4=B8=A6=E6=9B=B4=E6=96=B0=E7=8F=BE=E6=9C=89=E8=B3=87=E6=96=99?= =?UTF-8?q?=E7=82=BA=E5=95=9F=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ProductController.php | 8 ----- ...161624_add_is_active_to_products_table.php | 31 +++++++++++++++++++ .../seeders/UpdateProductsActiveSeeder.php | 14 +++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 database/migrations/tenant/2026_02_05_161624_add_is_active_to_products_table.php create mode 100644 database/seeders/UpdateProductsActiveSeeder.php diff --git a/app/Modules/Inventory/Controllers/ProductController.php b/app/Modules/Inventory/Controllers/ProductController.php index 7b8ee91..a9a0b8d 100644 --- a/app/Modules/Inventory/Controllers/ProductController.php +++ b/app/Modules/Inventory/Controllers/ProductController.php @@ -196,10 +196,6 @@ class ProductController extends Controller $validated['code'] = $this->generateRandomCode(); } - if (!isset($validated['is_active'])) { - $validated['is_active'] = true; - } - $product = Product::create($validated); return redirect()->route('products.index')->with('success', '商品已建立'); @@ -263,10 +259,6 @@ class ProductController extends Controller $validated['code'] = $this->generateRandomCode(); } - if (!isset($validated['is_active'])) { - $validated['is_active'] = true; - } - $product->update($validated); if ($request->input('from') === 'show') { diff --git a/database/migrations/tenant/2026_02_05_161624_add_is_active_to_products_table.php b/database/migrations/tenant/2026_02_05_161624_add_is_active_to_products_table.php new file mode 100644 index 0000000..15f01d7 --- /dev/null +++ b/database/migrations/tenant/2026_02_05_161624_add_is_active_to_products_table.php @@ -0,0 +1,31 @@ +boolean('is_active')->default(true)->after('wholesale_price')->comment('是否啟用'); + }); + + // 更新現有資料為啟用 + \DB::table('products')->whereNull('is_active')->orWhere('is_active', false)->update(['is_active' => true]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('is_active'); + }); + } +}; diff --git a/database/seeders/UpdateProductsActiveSeeder.php b/database/seeders/UpdateProductsActiveSeeder.php new file mode 100644 index 0000000..3ef4c6c --- /dev/null +++ b/database/seeders/UpdateProductsActiveSeeder.php @@ -0,0 +1,14 @@ +update(['is_active' => true]); + } +}