My data is like this
After re-saving the data is saved two double.
public function store(Request $request) { foreach ($request->name as $key => $name) { Setting::firstOrCreate( ['name' => $name], ['link' => $request->link[$key]] ); } return redirect()->route('settings.index'); }
Advertisement
Answer
you need to used updateOrCreate method instead of firstOrCreate
public function store(Request $request) { foreach ($request->name as $key => $name) { Setting::updateOrCreate( ['name' => $name], ['link' => $request->link[$key]] ); } return redirect()->route('settings.index'); }
for more information read this article https://eloquentbyexample.com/course/lesson/lesson-7-creating-and-updating