#59 Laravel 11 Tutorial with MongoDB | Product Listing (II) | Show Category Breadcrumb | Pagination
Автор: Stack Developers
Загружено: 2024-06-11
Просмотров: 121
Описание:
►Laravel 11 Tutorial (with MongoDB): • Laravel 11 Tutorial (with MongoDB)
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.
1) Update listing.blade.php file :-
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.
3) Update listing.blade.php file:-
Now update the listing.blade.php file to show breadcrumbs that we have generated both for the main and sub-category.
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.
5) Update listing.blade.php file :-
Now we will use the links method of pagination at listing.blade.php file that will display the links of the rest of the pages in which we are showing a maximum 6 products. And, HTML generated by the links method is compatible with the Bootstrap CSS framework.
Now, we can see in the video that pagination has come now and a maximum of 6 products are displayed on 1 page.
6) Update AppServiceProvider.php file:-
To add bootstrap to the Pagination Class everywhere on our Laravel website, we will include the Paginator class in the AppServiceProvider.php file and also load the useBootstrap object at the boot function.
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.
►Click here to subscribe for Laravel & other updates - / stackdevelopers
Popular Stack Developers Series that can help you:
►Laravel 10 Tutorial Playlist: • Laravel 10 Tutorial: Make Admin Panel / E-...
►Laravel Multi-Vendor E-commerce Website - • Laravel Multi Vendor Tutorial
►React JS Tutorial for Beginners with Laravel - • React JS Tutorial with Laravel for Beginners
►Laravel Tutorial for Beginners - • Laravel Tutorial for Beginners | Advance E...
►GIT Tutorial for Beginners - • Git Tutorial for Beginners | Create your F...
►Laravel API Tutorial - • Laravel API Tutorial | Create API from Scr...
►Laravel Interview Questions - • Laravel Interview Questions & Answers | 20...
►Join this channel to get the complete source code of all series:
/ @stackdevelopers
#laravel11 #laravel11tutorial #mongodb
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: