/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $today = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")) + 60 * 60 * 6.5);
     /*$validator = Validator::make($request->all(), [
                 'user_id'  => 'required|exists:competition_group_users,user_id',
             ]);
     
             if ($validator->fails()) {
                 if($validator->errors()->has('user_id'))
                     return response()->json("You are not TLG member.", 400);
             }*/
     $competition_question = CompetitionQuestion::where('start_date', '<=', $today)->where('end_date', '>=', $today)->orderBy('id', 'desc')->first();
     if ($competition_question) {
         $check = CompetitionGroupUser::where('competition_question_id', $competition_question->id)->where('user_id', $request->input('user_id'))->first();
         if (!$check) {
             return response()->json("You are not TLG member.", 400);
         }
         $multiple_question = MutipleQuestion::where('question_id', $competition_question->id)->get();
         foreach ($multiple_question as $key => $value) {
             $multiple_question[$key]['option'] = MutipleOption::where('mutiple_question_id', $value->id)->orderBy('option', 'asc')->get();
         }
         $group_user = CompetitionGroupUser::where('competition_question_id', $competition_question->id)->where('user_id', $request->input('user_id'))->first();
         if ($group_user) {
             $competition_question['group_user_id'] = $group_user->id;
         } else {
             $competition_question['group_user_id'] = 0;
         }
         $competition_question['multiple_question'] = $multiple_question;
         $datetime1 = new DateTime($today);
         $datetime2 = new DateTime($competition_question->end_date);
         $interval = $datetime1->diff($datetime2);
         $competition_question['day_left'] = $interval->format('%a');
         $competition_question['current_datetime'] = $today;
         return response()->json($competition_question);
     } else {
         $competition_answer = CompetitionAnswer::with('competitiongroupuser')->where('correct', true)->orderBy('id', 'desc')->get();
         if (count($competition_answer) > 0) {
             $answer_list = array();
             foreach ($competition_answer as $i => $answer) {
                 $answer['status'] = $answer['status'] == 1 ? true : false;
                 $answer['correct'] = $answer['correct'] == 1 ? true : false;
                 $answer_list[] = $answer;
             }
             $competition_question = CompetitionQuestion::where('id', $competition_answer[0]->question_id)->first();
             $competition_question['correct_answer'] = $answer_list;
             return response()->json($competition_question);
         }
         $game_msg['error'] = 'The next game will start on November 1.';
         $game_msg['error_mm'] = 'ေနာက္ ဂိမ္းကို ႏိုဝင္ဘာ ၁ ရက္ေန႕တြင္ စပါမည္။';
         return response()->json($game_msg, 403);
     }
 }
 public function search($input)
 {
     $query = MutipleOption::query();
     $columns = Schema::getColumnListing('mutipleOptions');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }