select()->toArray(); $category = linear_to_tree($category, 'children'); return $this->data($category); } public function dishes() { $categoryId = $this->request->get('category_id'); $keyword = $this->request->get('keyword'); $query = Dishes::field('id,dishes_category_id,name,image,intro')->where('status', 1); if (!empty($categoryId)) { $query->where('dishes_category_id', $categoryId); } if (!empty($keyword)) { $query->whereLike('name', "%$keyword%"); } $data = $query->select()->toArray(); return $this->data($data); } public function detail() { $id = $this->request->get('id'); $data = Dishes::with(['dishesProduct' => function ($query) { $query->with(['product', 'unit']); }])->where('id', $id)->where('status', 1)->find(); if (empty($data)) { return $this->fail('菜品不存在'); } $data = $data->toArray(); return $this->data($data); } }