public function checkAnswer()
 {
     $question = Question::findOrFail(Input::get('question_id'));
     if ($question->correct_answer_id == Input::get('answer_id')) {
         $user = User::findOrFail(Auth::user()->id);
         $user->correct_answers_count++;
         $user->save();
         return ['isValid' => true];
     } else {
         return ['isValid' => false];
     }
 }
예제 #2
0
 public function edit()
 {
     $questions = Question::findOrFail($id);
     return view('questionbank::edit', compact('id', 'type', 'difficulty', 'level', 'questions'));
 }
예제 #3
0
 public function getNextQuestion($index)
 {
     if (Input::has('cat')) {
         $questions = Question::where('category', '=', Input::get('cat'))->get();
         foreach ($questions as $question) {
             $questionArray[] = $question->id;
         }
         $nextQuestion = Question::findOrFail($questionArray[$index]);
         return Response::json($nextQuestion);
     } else {
         $questions = Question::all();
         foreach ($questions as $question) {
             $questionArray[] = $question->id;
         }
         $nextQuestion = Question::findOrFail($questionArray[$index]);
         return Response::json($nextQuestion);
     }
 }