Get nodes of specified level of node
minhchu opened this issue · comments
Minh Chu commented
Hi, thanks for making great package.
I have a question. How can I get nodes of specified level of a node ?
For example:
$result = Category::withDepth()->find($nodeId)->descendants->having('depth', '=', 1)->get();
Egor Gruzdev commented
$result = Category::query()->where('depth', 1)->get();
Minh Chu commented
Hi @EgorGruzdev
It does not work because depth
is not a real column in the database.
Just found the solution:
Category::first()->descendants()->withDepth()->having('depth', 1)->get()
Egor Gruzdev commented
I'm sorry, but indeed there is no depth column in this package (confused with https://github.com/etrepat/baum).
Minh Chu commented
@EgorGruzdev yep, you can see it in the docs: https://github.com/lazychaser/laravel-nestedset#including-node-depth
Btw, I've just updated my previous comment. Thanks