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]); + } +}