/** * api function get answers for a questions * * @param $request the request * @param int $qid the question for which to fetch answers * @return json the answers json object */ public function all(Request $request, $qId) { if (!Auth::check()) { return Response::json(['error' => ['message' => 'not authorized, not logged in']]); } else { if (!Auth::user()->isAdmin()) { return Response::json(['error' => ['message' => 'not authorized, elevated permissions needed']]); } } $answerCount = Answer::count(); // get the questions for that page $answers = Answer::where('question_id', $qId)->get(); $result = array('answers' => $answers, 'answerCount' => $answerCount, 'qId' => $qId); return $result; }