faq; $looplimit = count($faq); for ($i = 0; $i < $looplimit; $i++) { $faqToInsert = !empty($faq[$i]["question"]) && !empty($faq[$i]["answer"]); if (isset($faq[$i]["id"]) && $faq[$i]["id"] !== null && $faqToInsert) { $f = Faq::findOrFail($faq[$i]["id"]); $f->question = $faq[$i]["question"]; $f->answer = $faq[$i]["answer"]; $f->save(); } else { if ($faqToInsert) { $c = Faq::updateOrCreate([ 'question' => $faq[$i]["question"], 'answer' => $faq[$i]["answer"] ]); $faq[$i]["id"] = $c->id; } else { unset($faq[$i]); $i--; } } } return $faq; } /** * Remove the specified resource from storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function destroy(Request $request) { $faq = Faq::findOrFail($request->id); $faq->delete(); return "Suppression terminée !"; } }