Beispiel #1
0
 public function store(AnswerRequest $request)
 {
     $question = Question::findOrFail($request->input('question_id'));
     $this->authorize('view-course', $question->course);
     $answer = new Answer($request->only(['body']));
     $answer->question()->associate($question);
     $answer->user()->associate(auth()->user());
     $answer->save();
     session()->flash('success', 'La respuesta ha sido enviada.');
     return redirect()->back();
 }
 public function store(Request $request, $lecture_id, $subject_id, $topic_id, $knowledgeunit_id, $question_id)
 {
     $this->validate($request, ['description' => 'required']);
     $question = Question::find($question_id);
     Log::info('$knowledgeUnit: ' . $question->title);
     $answer = new Answer();
     $answer->correct = $request->correct ? $request->correct : 0;
     $answer->description = $request->description;
     $answer->question()->associate($question);
     $answer->save();
     return redirect('/lectures/' . $lecture_id . '/subjects/' . $subject_id . '/topics/' . $topic_id . '/knowledgeunits/' . $knowledgeunit_id . '/questions/' . $question_id . '/answers');
 }
Beispiel #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int     $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $question = Question::findOrFail($id);
     $question->question = $request->get('question');
     $question->save();
     $question->answers()->delete();
     foreach ($request->get('choice') as $key => $choice) {
         $answer = new Answer();
         $answer->type = "string";
         $answer->textual = $choice;
         $answer->correct = in_array($key + 1, $request->get('answer')) <=> 0;
         $answer->question()->associate($question);
         $answer->save();
     }
     return redirect()->to(route("paper.edit", $question->paper->id));
 }