Пример #1
0
 public function viewSearch(Request $request)
 {
     $input = $request->all();
     $questions = Question::where('question', 'LIKE', '%' . $input['search'] . '%')->orWhere('answer', 'LIKE', '%' . $input['search'] . '%')->select('question', 'answer')->get();
     $specialquestions = Specialquestion::where('question', 'LIKE', '%' . $input['search'] . '%')->orWhere('answer', 'LIKE', '%' . $input['search'] . '%')->select('question', 'answer')->get();
     return view('admin/search')->with(['questions' => $questions, 'specialquestions' => $specialquestions, 'string' => $input['search']]);
 }
Пример #2
0
 public function submitSpecialQuiz(Request $request)
 {
     $input = $request->all();
     $inputs = [];
     foreach ($input as $key => $value) {
         if (substr($key, 0, strlen('answer')) === 'answer') {
             $inputs[$key] = 'required';
             $question_id = explode('_', $key)[1];
         }
     }
     $inputs['banker'] = ['max:5'];
     $this->validate($request, $inputs);
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $user_id = Auth::user()->id;
     foreach ($inputs as $key => $validation) {
         if (substr($key, 0, strlen('answer')) === 'answer') {
             $question_id = explode('_', $key)[1];
             $specialquestion = Specialquestion::find($question_id);
             $specialquiz = Specialquiz::find($specialquestion->quiz_id);
             if (!($specialquiz->year == $year && $specialquiz->month == $month && $specialquiz->day == $day)) {
                 return redirect()->route('specialquiz');
             }
             $answer = Specialanswer::where('question_id', $question_id)->where('user_id', $user_id)->where('submitted', 1)->get();
             if (isset($input['banker']) && in_array($question_id, $input['banker'])) {
                 $banker = 1;
             } else {
                 $banker = 0;
             }
             if (!count($answer)) {
                 Specialanswer::create(['question_id' => $question_id, 'user_id' => $user_id, 'answer' => $input[$key], 'banker' => $banker, 'submitted' => 1]);
             }
         }
     }
     return redirect()->route('specialquiz');
 }