MongoDB Laravel | Make E-commerce #81: Laravel Helpers | Create Helper Function for Cart Items Count

preview_player
Показать описание

This is Part 81 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 create Helpers where we can create all common functions.

We will create a common function totalCartItems in the Helpers file that we can use anywhere on our website to show the total items added to user shopping cart.

3) Run below composer command :-
composer dump-autoload

4) Create totalCartItems function :-

5) Include Cart model :-

7) Update updateCartItemQty function :-
Now we will update updateCartItemQty function located at ProductsController to call totalCartItems function to get total cart items count and return to Ajax response from where we will display with class totalCartItems.

8) Update deleteCartItem function :-
Now we will update deleteCartItem function to call totalCartItems function to get total cart items count and return to Ajax response from where we will display with class totalCartItems.

Now check in video, We able to show total cart items count at header, sidebar and in shopping cart. Count updates without refresh.

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 #mongodb #mongodbtutorial
Рекомендации по теме