Ejemplo n.º 1
0
 /**
  * Displays appropriate question to the user
  *
  * @param null $category
  * @return \Illuminate\Http\RedirectResponse|
  * \Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function show($category = null)
 {
     $id = \Auth::id();
     $answered_questions = \DB::table('question_user')->where('user_id', '=', $id)->get(array('question_id'));
     $answered_questions = json_decode(json_encode($answered_questions), true);
     $categories = ['history', 'sports', 'science', 'literature', 'politics'];
     if ($category == null) {
         $question = Question::eligible($id, $answered_questions)->get()->toArray();
     } else {
         if (in_array($category, $categories)) {
             $question = Question::where('category', '=', $category)->eligible($id, $answered_questions)->get()->toArray();
         } else {
             \Session::flash('heading', 'Oops!!');
             \Session::flash('message', 'You are trying to access a wrong category');
             return redirect('/');
         }
     }
     return view('play.index', compact('question', 'category'));
 }