filmov
tv
#23 Make E-com website in Laravel 5.6 | #34 Admin Panel | Display Categories at Left Sidebar

Показать описание
In Part 23, we are going to display Categories and Sub Categories dynamically at left sidebar of home page.
There are 2 ways of doing this task :-
1) Basic Approach (Without Relations)
2) Advance Approach (With Relations, Recommended)
1) Basic Approach (Without Relations) :-
1.1) Update index function :-
1.2) Update Headers :-
use App\Category;
1.3) Update index function :-
Now see we are getting all categories and sub categories. And now we will create one variable in which we will add all these categories and sub categories with html that we are using to display at home page.
Now remove all html part and simply add $categories_menu variable that we have generated in index function.
Please correct all JS paths before proceed further.
Just open front_design blade file and make sure your JS paths looks like below for all js:
And after that it will work fine..
Now see, all categories and sub categories are coming at left side of home page correctly.
2) Advance Approach (With Relations, Recommended)
2.1) Update Category Model
2.2) Update index function
Update categories query with this relation categories by adding with('categories') in query.
Now remove $categories_menu that we have added earlier and add foreach loops in html only.
See now in video, our categories and sub categories are coming fine. And this approach with relation is more user friendly and faster/easier to do.
In next video, we will start working on category pages in which only products of that category will come..
So, stay tune for next video...
Thanks for watching :)
Комментарии