Insert array values into database in laravel
You're inserting into DB just one answer, the last one. Also, you can prepare the data and insert all the answers with just one query:
public function store(Request $request)
{
for ($i = 1; $i < count($request->en_answer); $i++) {
$answers[] = [
'user_id' => Sentinel::getUser()->id,
'en_answer' => $request->en_answer[$i],
'question_id' => $request->question_id[$i]
];
}
EnAnswer::insert($answers);
return redirect('submitted')->with('status', 'Your answers successfully submitted');
}