Beispiel #1
0
 public function store(CreateExamRequest $request)
 {
     if (!semester()) {
         return redirect()->route()->with('error', 'لم تقم بانشاء اي فصول افتراضية');
     }
     $exam = new Exam();
     $exam->fill($request->all());
     $exam->semester_id = semester()->id;
     $input = $request->all();
     if (!$exam->save()) {
         return redirect()->back()->with('error', trans('exams::exams.create_error'));
     }
     if ($request->has('number_of_questions')) {
         $questions_ids = $this->generateQuestions($request);
         $exam->questions()->sync($questions_ids);
     }
     $success_message = trans('exams::exams.create_success');
     if (isset($input['submit']) and $input['submit'] == 'exit') {
         return redirect()->route('exams.exams.index')->with('success', $success_message);
     } else {
         return redirect()->route('exams.exams.create')->with('success', $success_message);
     }
 }