Return to homepage
01/01. Quick and Easy Nested Categories in Laravel



Hi Alex or fellow Code course followers. I am trying to build a multi level drop down menu using this logic, CTE package and alpine. I am stuck and need some direction. I need to dynamically create the x-show classes, and cant figure it out. I have a menus models with parent ids, just like in this video and will appreciate some direction. Any help you can give me will be appreciated.

  • 0

Alex, or anyone, how would you then route those categories? So if I wanted to be able to click on a category and view a page for it, what would that look like in the routes file if I wanted to keep the hierarchy of the nested levels? So using the final category list in the lesson, you would click on Child 5 and the url would be /child-1/child-2/child-3/child-5.

  • 0

hi, what client do you use for sql?

  • 0

I have a question, In Ecommerce, there is Top product category (parent category), Subcategory ( second level category) and child category (sub-sub category), how do we differentiate between Subcategory and Child category.

Imagine that I am adding a new product and I can easily get the parent category by saying "select * from category where parent_id is null". How then do we get the sub category on without the child category because if we do "select * from category where parent_id is not null", it will fetch the result of both Subcategory and Child category?

The method I have been using before is by having a separate table for Top Category, another table for Sub-category and another for Child-category. Since everything is in the same table, how do we solve the issue above

  • 0

There is a depth() method you can use.

  • 0

Great video. Thank you

  • 2

Hey Alex, why don't you add a standalone 'LIKE' button for videos, because sometime we need to give a like when we don't have much to type in the comment box? Thanks for the snippet.

  • 4

Thanks for the suggestion Ahmed!

  • 0

Awesome, thank you, Alex, for the great overview of the adjacency list approach of building nested categories and the great feature rich package.

Could you please consider to continue this topic for SPA (preferable Vue/Laravel)? F.ex. to use the current approach for the API requests and connect with some front-end solution (custom or useful package) to manage tree and get the hierarchy data synced.


  • 8