filmov
tv
Laravel 11 Tutorial #76: E-com with Laravel / MongoDB | Shopping Cart (I) | HTML to Laravel Blade

Показать описание
This is Part 76 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.
From this part, we will start working on the shopping cart page where we will show cart items.
In this part, we will convert the shopping cart HTML page to a blade file of Laravel.
Cart Page
- Convert the Shopping Cart HTML Page to Laravel Blade
- Show Cart Items with Image/Details/Price
We will start working on building a shopping cart page so the first step is to merge the shopping cart page design.
1) Create Route:-
// Cart Route
Route::get('/cart',[ProductFrontController::class,'cart']);
2) Create cart function:-
Now create the cart function in ProductController that will return to the cart blade file that we will create in the next step.
Now, we are going to show cart items in the foreach loop by comparing them with the user session id.
4) Create getCartItems function :-
Update Cart model with getCartItems function in which we will get cart items or products by checking first user auth and if auth is not available means the user is not logged in then with a user session.
5) Update cart function :-
Now we will update the cart function in which we will call getCartItems and print to check if all user items are coming with a user session.
6) Create Relation:-
Now we will create a relation between carts and products table for getting the detail of the product so add the product relation function in the Cart model with belongsTo relation. And we will add brand and images relation to it to get complete product and image details.
7) Update getCartItems function :-
Now we will update the getCartItems function to attach the product relation so that we will get complete product details with every cart item.
Now update the cart blade file with foreach loop to show all cart items added by the user without logging in with the session id.
9) Include Session & Auth at the top of Cart model:
use Session;
use Auth;
In the next video, we will show the discounted price for the cart items and will also show the Sub Total and Grand Total of the products.
Popular Stack Developers Series that can help you:-
►Join this channel to get the complete source code of all series:
Follow Stack Developers on Social Media to get updates and resolve your queries
#laravel11 #laravel11tutorial #mongodbtutorial