Ejemplo n.º 1
0
 public function store(Question $question, choiceRequest $req, Choice $choiceModel)
 {
     $countchoice = 0;
     $msgdanger = 'لا تستطيع اضافة اجابة للسؤال المقالي';
     if ($question->type == 'essay') {
         return redirect()->back()->with('error', $msgdanger);
     }
     if ($question->type == 'true_false') {
         $countchoice = $choiceModel->where('question_id', $question->id)->count();
         $msgerrorTrueFalse = 'لا تستطيع اضافة اكثر من اجابتين للسؤال الصح والخطاء';
         if ($countchoice > 1) {
             return redirect()->back()->with('error', $msgerrorTrueFalse);
         }
     }
     if ($question->type != 'multiple_choice' and $req->input('istrue') == 1) {
         $choice = $choiceModel->where('question_id', $question->id);
         $choice->update(['istrue' => 0]);
     }
     $choice = $choiceModel->fill($req->all());
     $choice->save();
     $message = 'تم اضافة الاجابة بنجاح';
     if (request('submit') == 'save' and $countchoice < 1) {
         return redirect()->back()->with('success', $message);
     } else {
         return redirect()->route('choice.index', array('qid' => $question->id))->with('success', $message);
     }
 }