validate([ 'title' => 'required|string|max:255', 'content' => 'required|string', ]); Post::create($validated); return redirect()->route('posts.index')->with('success', 'Post created successfully.'); } public function show(Post $post) { return view('posts.show', compact('post')); } public function edit(Post $post) { return view('posts.edit', compact('post')); } public function update(Request $request, Post $post) { $validated = $request->validate([ 'title' => 'required|string|max:255', 'content' => 'required|string', ]); $post->update($validated); return redirect()->route('posts.index')->with('success', 'Post updated successfully.'); } public function destroy(Post $post) { $post->delete(); return redirect()->route('posts.index')->with('success', 'Post deleted successfully.'); } }