public function storequestion(Question $question, Request $req, $subjectid) { $question->fill($req->all())->save(); $message = 'تم اضافة السؤال بنجاح'; if (request('submit') == 'save') { return redirect()->route('choice.create', array('id' => $question->id))->with('success', $message); } else { return redirect()->route('questionbank.questionlistsub', array('id' => $subjectid))->with('success', $message); } }
public function storequestion(QuestionRequest $request, $activity_id) { $question = new Question(); Session::put('typeQ', $request->get('type')); $question->fill($request->all()); $question->user_id = teacher()->id; $question->save(); $exam = Exam::findOrFail($activity_id); $exam->questions()->detach($question->id); $exam->questions()->attach($question->id); $choices = $request->input('choices'); if (!empty($choices)) { //not essay foreach ($choices as $key => $choice) { if ($request->get('type') != 'multiple_choice') { if ($request->input('choices_correct_new_00') == $key) { // TF or Single choice $istrue = 1; } else { $istrue = 0; } } else { if (!empty($request->choices_correct_new)) { //multiple_choice //if(!empty($request->choices_correct_new)) if (array_key_exists($key, $request->choices_correct_new)) { $istrue = 1; } else { $istrue = 0; } //$istrue = $request->input('choices_correct_new['.$key.']'); } else { $istrue = 0; } } Choice::create(['choice' => $choice, 'question_id' => $question->id, 'istrue' => $istrue]); } } $message = 'تم اضافة السؤال بنجاح'; if (request('submit') == 'save') { return redirect()->route('teachers.profile.createquestion', array('id' => $activity_id))->with('success', $message); } else { $request->session()->forget('typeQ'); return redirect()->route('teachers.profile.questions', array('id' => $activity_id))->with('success', $message); } }
public function store(QuestionRequest $request, $subject_id) { $question = new Question(); Session::put('typeQ', $request->get('type')); Session::put('difficultyQ', $request->get('difficulty')); Session::put('levelQ', $request->get('level')); $question->fill($request->all()); $question->user_id = user()->id; $question->save(); $choices = $request->input('choices'); if (!empty($choices)) { //not essay foreach ($choices as $key => $choice) { if ($request->get('type') != 'multiple_choice') { if ($request->input('choices_correct_new_00') == $key) { // TF or Single choice $istrue = 1; } else { $istrue = 0; } } else { if (!empty($request->choices_correct_new)) { //multiple_choice //if(!empty($request->choices_correct_new)) if (array_key_exists($key, $request->choices_correct_new)) { $istrue = 1; } else { $istrue = 0; } //$istrue = $request->input('choices_correct_new['.$key.']'); } else { $istrue = 0; } } Choice::create(['choice' => $choice, 'question_id' => $question->id, 'istrue' => $istrue]); } } $message = 'تم اضافة السؤال بنجاح'; if (request('submit') == 'save') { return redirect()->route('questionbank.create', array('id' => $subject_id))->with('success', $message); } else { // $request->session()->forget('typeQ'); return redirect()->route('questionbank.question', array('id' => $subject_id))->with('success', $message); } }