get()->map(function ($faq) { return [ 'id' => $faq->id, 'question' => $faq->question, 'answer' => $faq->answer, 'category' => $faq->category, 'is_published' => (bool)$faq->is_published, 'created_at' => $faq->created_at->format('Y-m-d H:i'), ]; }); return Inertia::render('Admin/Faqs/Index', [ 'faqs' => $faqs ]); } public function store(Request $request) { $request->validate([ 'question' => 'required|string|max:1000', 'answer' => 'required|string|max:5000', 'category' => 'nullable|string|max:255', 'is_published' => 'boolean' ]); $question = trim($request->question); if (!str_ends_with($question, '?')) { $question .= '?'; } Faq::create([ 'question' => $question, 'answer' => $request->answer, 'category' => $request->category ?: 'General', 'is_published' => $request->has('is_published') ? $request->is_published : true, ]); return redirect()->back()->with('success', 'FAQ created successfully.'); } public function update(Request $request, $id) { $faq = Faq::findOrFail($id); $request->validate([ 'question' => 'required|string|max:1000', 'answer' => 'required|string|max:5000', 'category' => 'nullable|string|max:255', 'is_published' => 'boolean' ]); $question = trim($request->question); if (!str_ends_with($question, '?')) { $question .= '?'; } $faq->update([ 'question' => $question, 'answer' => $request->answer, 'category' => $request->category ?: 'General', 'is_published' => $request->has('is_published') ? $request->is_published : true, ]); return redirect()->back()->with('success', 'FAQ updated successfully.'); } public function destroy($id) { $faq = Faq::findOrFail($id); $faq->delete(); return redirect()->back()->with('success', 'FAQ deleted successfully.'); } }