input('limit', 10))); $query = Question::query(); if ($kpCode = $request->string('kp_code')->toString()) { $query->where('kp_code', $kpCode); } if ($type = $request->string('question_type')->toString()) { $query->where('question_type', $type); } $questions = $query->inRandomOrder()->limit($limit)->get(); return response()->json([ 'count' => $questions->count(), 'data' => $questions, ]); } }