public function update($id, Request $request) { $question = Question::findOrFail($id); foreach ($request->choices as $choice) { $choiceModels[] = new Choice(['choice_text' => $choice]); } $data = $request->all(); $data["user_id"] = \Auth::user()->id; Choice::where("question_id", $id)->delete(); $question->update($data); $question->choices()->saveMany($choiceModels); session()->flash('flash_msg', 'You have successfully added a poll.'); return redirect('/'); }