Files
yuezi-saas/backend/app/Http/Controllers/Admin/Meal/DishController.php
T
li 16bcd9bcf0 feat: 第二阶段核心业务模块(CRM/房务/护理/月子餐)
后端:
- 4个迁移文件新增23张业务表
- 23个Eloquent Model(含关联/类型转换/门店隔离)
- 20个Controller(含CRUD+业务操作: 合同审核/入住退房/护理异常处理等)
- 110+条API路由(crm/room/care/meal四大前缀)

前端:
- 4个API模块(crm.js/room.js/care.js/meal.js)
- 13个业务页面(线索/客户/合同/渠道/投诉/房型/房间/预定/护理档案/护理计划/护理记录/菜品/排餐)
2026-03-13 20:18:29 +08:00

64 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Meal;
use App\Http\Controllers\Controller;
use App\Models\Meal\Dish;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DishController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Dish::query();
$query->when($request->name, fn($q, $v) => $q->where('name', 'like', "%{$v}%"));
$query->when($request->category, fn($q, $v) => $q->where('category', $v));
$query->when($request->has('status'), fn($q) => $q->where('status', $request->status));
return $this->paginate($query->latest()->paginate($request->input('per_page', 15)));
}
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'name' => 'required|string|max:50',
'category' => 'nullable|string|max:30',
'description' => 'nullable|string',
'image' => 'nullable|string|max:255',
'ingredients' => 'nullable|array',
'contraindications' => 'nullable|array',
'price' => 'sometimes|numeric|min:0',
'status' => 'sometimes|integer|in:0,1',
]);
return $this->success(Dish::create($validated));
}
public function show(Dish $dish): JsonResponse
{
return $this->success($dish);
}
public function update(Request $request, Dish $dish): JsonResponse
{
$validated = $request->validate([
'name' => 'sometimes|string|max:50',
'category' => 'nullable|string|max:30',
'description' => 'nullable|string',
'image' => 'nullable|string|max:255',
'ingredients' => 'nullable|array',
'contraindications' => 'nullable|array',
'price' => 'sometimes|numeric|min:0',
'status' => 'sometimes|integer|in:0,1',
]);
$dish->update($validated);
return $this->success($dish);
}
public function destroy(Dish $dish): JsonResponse
{
$dish->delete();
return $this->success(null);
}
}