Laravel with MongoDB CURD operations - part 3
You have already save data to post collection on mongodb. Now we are going to display all the post in your web page. We have already created the route /post to display all posts. You need to use index method in your PostController to write a method to display all posts. Now add following code to get all posts and display them in the view. /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $posts = Post::all(); return view('posts.index')->with('posts', $posts); } If you go to {YOUR_BASE_URL}/posts you will get an error as you haven't add index view yet. Now will add the view. Go to resources/views/posts and add a file "index.blade.php" Add code like following to display your all posts title. <!DOCTYPE html> ...