get(); return view('forum.index', compact('categories')); } /** * Show the form for creating a new resource. */ public function create() { // This would be restricted to admins in a middleware return view('forum.categories.create'); } /** * Store a newly created resource in storage. */ public function store(Request $request) { // This would be restricted to admins in a middleware $validated = $request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'order' => 'nullable|integer', ]); $validated['slug'] = Str::slug($validated['name']); ForumCategory::create($validated); return redirect()->route('forum.index') ->with('success', 'Category created successfully.'); } /** * Display the specified resource. */ public function show(ForumCategory $category) { $threads = $category->threads() ->with('user') ->orderBy('is_sticky', 'desc') ->orderBy('last_activity_at', 'desc') ->paginate(20); return view('forum.categories.show', compact('category', 'threads')); } /** * Show the form for editing the specified resource. */ public function edit(ForumCategory $category) { // This would be restricted to admins in a middleware return view('forum.categories.edit', compact('category')); } /** * Update the specified resource in storage. */ public function update(Request $request, ForumCategory $category) { // This would be restricted to admins in a middleware $validated = $request->validate([ 'name' => 'required|string|max:255', 'description' => 'nullable|string', 'order' => 'nullable|integer', ]); if ($request->name !== $category->name) { $validated['slug'] = Str::slug($validated['name']); } $category->update($validated); return redirect()->route('forum.index') ->with('success', 'Category updated successfully.'); } /** * Remove the specified resource from storage. */ public function destroy(ForumCategory $category) { // This would be restricted to admins in a middleware $category->delete(); return redirect()->route('forum.index') ->with('success', 'Category deleted successfully.'); } }