- 修正所有模組 Controller 的 Model 引用路徑 (App\Modules\...) - 更新 ProductionOrder 與 ProductionOrderItem 模型結構以符合新版邏輯 - 修復 resources/js/utils/format.ts 在處理空值時導致 toLocaleString 崩潰的問題 - 清除全域路徑與 Controller 遷移殘留檔案
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Inventory\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Modules\Inventory\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255|unique:categories,name',
|
|
]);
|
|
|
|
Category::create([
|
|
'name' => $validated['name'],
|
|
'is_active' => true,
|
|
]);
|
|
|
|
return redirect()->back()->with('success', '分類已建立');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Category $category)
|
|
{
|
|
$validated = $request->validate([
|
|
'name' => 'required|string|max:255|unique:categories,name,' . $category->id,
|
|
]);
|
|
|
|
$category->update($validated);
|
|
|
|
return redirect()->back()->with('success', '分類已更新');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Category $category)
|
|
{
|
|
if ($category->products()->count() > 0) {
|
|
return redirect()->back()->with('error', '該分類下尚有商品,無法刪除');
|
|
}
|
|
|
|
$category->delete();
|
|
|
|
return redirect()->back()->with('success', '分類已刪除');
|
|
}
|
|
}
|