Querying depth #193
-
Hey there, I'm here again to ask for help. I want to get all the parents for the given depth because I'll use it to scan if the parents in that depth have children but using I'm expecting this to get the parents where I use
Given this example data returned by
I did try adding It returns the parents in that depth but the children are empty array even though that parent has children.
The query above returns the data below, notice that the children are an empty array even though that parent has children (see the complete data returned by
Is there a way to get the parents for the given depth and also get the Level 1 children of those parents? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @whoami15, Try this instead: $tree = Account::query()
->treeOf($constraint)
->whereDepth('>=', 2)
->whereDepth('<=', 3)
->get()
->toTree(); |
Beta Was this translation helpful? Give feedback.
Hi @whoami15,
toTree()
"only" rearranges the query result.whereDepth(2)
removes the children from the query result and that's whychildren
is empty.Try this instead: