etrepat / baum

Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.
http://etrepat.com/baum
MIT License
2.24k stars 460 forks source link

Is there any other method to check if node has child? #157

Closed azulkipli closed 9 years ago

azulkipli commented 9 years ago

Hi, Thanks for creating this package.

I use this package for dynamic hierarchy Menu Item.

Currently I use this method to check if node has child ;

if (count($node->children()->get()) > 0 )

if (count($node->getDescendants()) > 0 )

When I am doing this method, this is running query as many as node in the loop.

Any other best method to check if node has child without query to database, such as isRoot(), isLeaf() ?

Thanks

etrepat commented 9 years ago

You could definitely use isLeaf() here. https://github.com/etrepat/baum#node-questions

azulkipli commented 9 years ago

Oh I think I miss this line, thanks

isLeaf(): Returns true if this is a leaf node (end of a branch).