Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

There is no prepared methods? I must use array_walk_recursive?


I have the exact identical question.

How did you resolved finally?


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


Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Aneta1990 aneta1990 Joined 3 Mar 2016


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.