get(); $posts = Post::latest()->get(); return view('posts.index', compact('posts')); } public function show(Post $post) { return view('posts.show', compact('post')); } /** * Store a newly created resource in storage. * * - Create new post using the request data * - Save it to the database * - Redirect to the home page * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(Request $request) { // $post = new Post(); // $post->title = $request->get('title'); // $post->body = $request->get('body'); // $post->save(); $this->validate($request, [ 'title' => 'required|min:10', 'body' => 'required', ]); Post::create([ 'title' => $request->get('title'), 'body' => $request->get('body'), ]); return redirect('/'); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } }