lazychaser / laravel-nestedset

Effective tree structures in Laravel 4-8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get nodes of specified level of node

minhchu opened this issue · comments

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();
$result = Category::query()->where('depth', 1)->get();

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()

I'm sorry, but indeed there is no depth column in this package (confused with https://github.com/etrepat/baum).

@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