Skip to content

Querying depth #193

Answered by staudenmeir
whoami15 asked this question in Q&A
Sep 5, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @whoami15,
toTree() "only" rearranges the query result. whereDepth(2) removes the children from the query result and that's why children is empty.

Try this instead:

$tree = Account::query()
    ->treeOf($constraint)
    ->whereDepth('>=', 2)
    ->whereDepth('<=', 3)
    ->get()
   ->toTree();

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@whoami15
Comment options

Answer selected by whoami15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants