From the course: Laravel Essential Training
Unlock the full course today
Join today to access over 25,000 courses taught by industry experts.
Add pagination and clean up the index view - Laravel Tutorial
From the course: Laravel Essential Training
Add pagination and clean up the index view
Currently, we're fetching all the notes of the user and passing them to the view. But what if the user has hundreds of notes? We surely need pagination. Since it's very common to add pagination, Laravel has made it very easy for us. Just replace get here with paginate and pass the count of items you'd like to display in a page. And just for demonstration, let me add 1 here. Save the file and refresh. As you can see, we have one single note, but we also need the links here for navigation. That's also easy. Just go to the view first. At the end, after foreach, you simply have to add $notes->links. Like so. And now refresh. Look at that. Out of the box, we get pagination. And all of this is styled using Tailwind CSS and all the links work as expected. If you wish to customize the styling, you can do so by passing your own pagination view right here. All right, now that we know it works, let's go back to our controller and change this to 5. Back to the browser. This view looks fine right…
Contents
-
-
-
-
-
-
(Locked)
Add an index method to fetch all notes5m 19s
-
(Locked)
Create an index view to display all notes5m 31s
-
(Locked)
Add pagination and clean up the index view4m 53s
-
(Locked)
Add a create method and view to show a form9m 42s
-
(Locked)
Add a store action to save the data7m 21s
-
(Locked)
Add a show action and view to display single note6m 40s
-
(Locked)
Create a unique ID for each note3m 50s
-
(Locked)
Challenge: Add index and create methods for a new resource53s
-
(Locked)
Solution: Add index and create methods for a new resource4m 46s
-
(Locked)
-
-
-
-