public function getQuiz($id) { $quizzes = Quiz::where('quiz_id', (int) $id)->with('user')->with('questions')->with('results')->with('media')->get(); $api = new ApiHandler(); $api->enableSideloading(); if ($quizzes->count() > 0) { $api->setCollection($quizzes); } else { $api->setState(404, 'not_found'); } return $api->send(); }
public function quesvalidate(Request $request, $qid) { $quiz = Quiz::where('question_id', $qid)->first(); $ans = $request->input('ansq'); $utoken = session('user_id'); if (strcasecmp($ans, $quiz['answer']) == 0) { $rid = $quiz['round']; solved::firstOrCreate(['user_token' => $utoken, 'question_no' => $qid, 'round_id' => $rid]); return redirect(url('/round/' . $rid)); } else { return view('quiz/ques')->with(['qid' => $qid, 'ques' => $quiz['question'], 'error' => 'Wrong Answer']); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $user = User::find(Auth::id()); if ($user->isExaminer()) { $quizzes = Quiz::where('user_id', $user->id)->latest()->get(); } else { if ($user->isExaminee()) { $quizzes = $user->availableQuizzes()->latest()->get(); } else { $quizzes = Quiz::latest()->get(); } } return view('quiz.index', compact('quizzes', 'user')); }
public function getAllAvailableQuizzes() { $today = Carbon\Carbon::now(); $today = Carbon\Carbon::create($today->year, $today->month, $today->day, 0, 0, 0); $quizzes = Quiz::where('valid_from', '<=', $today)->where('valid_to', '>=', $today)->get(); foreach ($quizzes as $quiz) { $result = QuizResults::where('quiz_id', '=', $quiz->id)->where('user_id', '=', \Auth::user()->id)->get(); if (!empty($result)) { $quiz->results = []; $quiz->results = $result; } } // $quizzes = Quiz::where('valid_from','<=',$today) // ->where('valid_to','>=',$today)->leftJoin('results', function($join) { // $join->on('quizzes.id','=','results.quiz_id')->where('results.user_id','=',\Auth::user()->id); // })->get(); return $quizzes; }
public function userQuizzes($id) { if (User::find($id) == null) { return response()->json(['error' => 'User does not exist'], 404); } $quizzes = Quiz::where('owner_id', $id)->get(); foreach ($quizzes as $quiz) { $quiz->owner_ref = "http://46.101.238.99/user/" . $quiz->owner_id; } return response()->json($quizzes, 200); }