/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $paper = Paper::findOrFail($request->get("paper_id")); $question = new Question(); $question->question = $request->get('question'); $question->language = "en"; $question->paper()->associate($paper); $question->save(); 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", $paper->id)); }