input('limit'); $keywords = $request->input('keywords', ''); $page = request()->input('page',1); $offset = ($page - 1) * $limit; $lists = Showroom::withCount(['viewer']) ->where('is_opened', 1) ->when($keywords, function ($query, $keywords) { /* @var Builder $query*/ return $query->where('name','like', "%$keywords%"); }) //->orderByDesc('viewer_count') ->orderByDesc('sort') ->limit($limit) ->offset($offset) ->get(); return $this->success($lists); } public function detail($id): JsonResponse { $info = Showroom::where('id',$id) ->first(); return $this->success($info); } public function viewer($id): JsonResponse { $stat = new StatShowroom(); $stat->showroom_id = $id; $stat->user_id = \user()->id; $stat->save(); return $this->success(); } }