Previous Video | Ecom Part 24: • #24 Make E-commerce website in Larave...
In Part 25, we will work on header menu that is common for all the pages at frontend of our Laravel project.
We will display main categories like T-Shirts and Shoes in header menu and will display all the products there.
Main Category T-Shirts can contain the products of below Sub Categories :-
Casual T-Shirts
Formal T-Shirts
Shoes :-
Sports Shoes
Formal Shoes
For adding common function, we will create this function in Controller.php file so that we can add this function to front_header to display in all the pages.
1) Create function :- (in Controller.php)
Create function this time in Controller.php so that we can include it in front header file that is common for all the frontend pages.
We will create mainCategories function where we will get all the main categories that is having parent id 0.
And this time we are going to add static function and return the variable.
2) Add Header :-
Add Header to include Category model at top of Controller.php file like below :-
use App\Category;
3) Update front_header.blade.php file :-
Now update front header blade file to get $mainCategories variable that we have returned in Controller.php file.
So we will add below PHP code at the top of front_header blade file:
use App\Http\Controllers\Controller;
$mainCategories = Controller::mainCategories();
Now we will add foreach loop to include main categories in header menu.
See now in video, our main categories are coming correctly in header menu with their url's but for showing products in main categories, we need to update products function in ProductsController.php file.
4) Update products function :-
Now we need to update products function in ProductsController.php file so that all products belonging to sub categories of main categories will come.
Uptill now we have displayed the products from sub category only like casual t-shirts or formal t-shirts but we are not showing any products in main category like t-shirts.
Now in products function, we will first check category url and on the basis of that url and if that url is main category url then we will display the products from all its sub category otherwise we will display the products from sub category only.
Sorry for the trouble... we will continue this part in next video as well.. I am going to add very soon...
In this video, we have added main categories in header menu and in next video we will show all the products even of their sub categories...
So stay tune for next video... thanks for watching..
CHECK NEXT VIDEO | Ecom Part 26 (ISSUE RESOLVED)
• #26 Make E-com website in Laravel 5.6...