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 459 forks source link

Detecting leftmost / rightmost #266

Closed sahamilton closed 3 months ago

sahamilton commented 7 years ago

Is there any method to detect if a node is the left most or right most of a set of siblings? I would like to ensure that a left most node is not moved to the left ( moveLeft() ) or a right most is not moved to the right (moveRight() ) Either case would cause an error

Could not resolve target node. This node cannot move any further to the left.

sahamilton commented 7 years ago

I solved this 'issue' by creating the two functions on the model

public function leftmost(){ return $this->parent()->first()->lft == $this->lft -1; } public function rightmost(){ return $this->parent()->first()->rgt == $this->rgt +1; }

and then test on that in the view

@if (! $page->leftmost() ) do something endif