DEV Community


Discussion on: How to create a nested-list of categories in Laravel blade

monaye profile image
Monaye Win

that will do pagination based on the count of the parent_id category.
I wanted to display the categories with a hierarchy. Ended up with this:

$categories = Category::where('level', 0)->with('descendants')->get()->flattenTree()->paginate(15);
Enter fullscreen mode Exit fullscreen mode

Image of hierarchy

Forem Open with the Forem app