Skip to content
Advertisement

How can show unlimited parent-child & sub-child tree data in laravel

I have data like parent-child with unlimited levels of sub-child & sub-child data in the database which you can see below like a binary tree with nodes that have multiple children and these children can have unlimited sub-child.

Please give me a solution or suggestion how can show that. Thanks.

This is my database JSON data which I’m getting from the database…

Controller Code

JavaScript
JavaScript

Edit: I want to equal the above data to this data

JavaScript

Advertisement

Answer

you need to fetch all the products in one query and then process them to build the tree. You cant eager load it the traditional way. Original solution from Formatink

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement