filmov
tv
#59 Laravel 11 Tutorial with MongoDB | Product Listing (II) | Show Category Breadcrumb | Pagination

Показать описание
This is Part 59 of the Laravel 11 Tutorial in which we are building the e-commerce website with Laravel as the front end and MongoDB as the back end.
In this part, we will show the category breadcrumb and the Laravel pagination to show limited products on one page.
First, we will update the listing file to show the products count at the top of the listing page.
2) Update categoryDetails function :-
Now we will update the categoryDetails function in the Category model to update the query to add breadcrumbs both for the main category and sub category.
If the main category is selected like shirts then only shirts will appear in the breadcrumb along with the home link and if the subcategory is selected like formal shirts then both shirts and formal shirts will appear in the breadcrumb along with the home link.
So we will add a condition with the parent_id of the category. If the parent_id of the category is 0 then the current category is the parent category. And if the parent_id of the category is greater than 0, it means the parent category of the current category exists.
Now, we will work on pagination for our listing page to show limited products on one page.
We will learn about Offset and Cursor Pagination. We will use simplePaginate, paginate, and cursorPaginate methods.
Offset Pagination
Offset pagination is one of the most widely used pagination techniques in the world today. Laravel’s paginate and simplePaginate methods on the Eloquent and database query builder classes use offset pagination under the hood.
Types of Offset Pagination:-
simplePaginate
paginate
Cursor Pagination
Cursor pagination is a high-performant pagination technique often used for large data-sets, infinite scrolling and APIs. Today’s Laravel release adds the cursorPaginate method to the Eloquent and database query builder classes, which uses cursor pagination under the hood.
Types of Cursor Pagination :-
cursorPaginate
Simple Pagination
If you only need to display simple "Next" and "Previous" links in your pagination view, you may use the simplePaginate method to perform a more efficient query.
Paginate Method:-
We will also integrate the Paginate method that will not only display "Next" and "Previous" links but also Page numbers like 1, 2, 3 and so on depending upon the number of products that you want to show on each page.
4) Update listing function:-
First of all, we will update the listing function to replace the get method and toArray with the paginate method in the query. We will also pass value 6 as an argument in the paginate method for a number of products we want to display "per page".
Now, we will try with simplePaginate method and then with paginate method. We need to remove get and toArray and then only add the paginate or simplePaginate method.
Now, we can see in the video that pagination has come now and a maximum of 6 products are displayed on 1 page.
In the next video, we will work on sorting filters for our listing page like displaying products in ascending/descending order in terms of product names and prices.
Popular Stack Developers Series that can help you:
►Join this channel to get the complete source code of all series:
#laravel11 #laravel11tutorial #mongodb