I would suggest using the correct schema setup for such a thing. Data in a hierarchy like this would require recursion unless using certain patterns to avoid this type of recursion. Especially when dealing with unknown depths.
Something like nested sets or closure table would be easier for querying to retrieve all descendents or parents, etc.
You could also go fancy use neo4j with graphs which then just traverse it for you. If you are going to do this quite frequent and you dont know how far it span - a graph approach might be good
Also the package for it is quite up to date up to Laravel 5.2 https://github.com/Vinelab/NeoEloquent
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community