public function isValid(Request $request)
 {
     $questionId = $request['questionId'];
     $answerId = $request['answerId'];
     $correctQuestionDB = Question::select('correct_answer_id')->findOrFail($questionId);
     if ($answerId == $correctQuestionDB->correct_answer_id) {
         $user = \Auth::user();
         $user->correct_answers++;
         $user->save();
         return 1;
     } else {
         return 0;
     }
 }
Exemplo n.º 2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $questions = Question::select('question', 'answer0', 'answer1', 'answer2', 'answer3', 'correct_answer', 'answer0_image', 'answer1_image', 'answer2_image', 'answer3_image')->get();
     $q = null;
     for ($j = 0; $j < count($questions); $j++) {
         $answers = null;
         $images = null;
         for ($i = 0; $i < 4; $i++) {
             $answers = array_add($answers, $i, ['id' => $i, 'text' => $questions[$j]['answer' . $i], 'image' => $questions[$j]['answer' . $i . '_image']]);
         }
         $q = array_add($q, $j, ['question' => $questions[$j]->question, 'answers' => $answers, 'correct' => $questions[$j]->correct_answer]);
     }
     return $q;
 }