laravel-nestedset
laravel-nestedset copied to clipboard
Modified assertNodeExists to perform null check
I've suddenly started running into issues where the root folder (which now has an _lft value of 0, and an _rgt value of 0) forces the assertNodeExists
method within NodeTrait
check to fail.
To better perform this test, we should check if the value returned from the models attribute is null as this is the value returned if the node doesn't exist.
The previous compiled test was running as -
if ( ! $node->getLft() || ! $node->getRgt()) { // if ( ! 0 || ! 0 )
throw new LogicException('Node must exists.');
}
So I was ending up with a Node must exists.
exception. Whereas $node->getLft()
and $node->getRgt()
actually return null if the values cannot be found. So I think a better check would be -
if ( is_null($node->getLft()) || is_null($node->getRgt()) ) {
throw new LogicException('Node must exists.');
}
I hope you'll consider this as a valid fix!