Skip to content

Commit bc2ef05

Browse files
committed
Merge
2 parents c06bae0 + afbb006 commit bc2ef05

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/NestedSet.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function columns(Blueprint $table)
4242
$table->unsignedInteger(self::RGT)->default(0);
4343
$table->unsignedInteger(self::PARENT_ID)->nullable();
4444

45-
$table->index(self::getDefaultColumns());
45+
$table->index(static::getDefaultColumns());
4646
}
4747

4848
/**
@@ -52,7 +52,7 @@ public static function columns(Blueprint $table)
5252
*/
5353
public static function dropColumns(Blueprint $table)
5454
{
55-
$columns = self::getDefaultColumns();
55+
$columns = static::getDefaultColumns();
5656

5757
$table->dropIndex($columns);
5858
$table->dropColumn($columns);
@@ -65,7 +65,7 @@ public static function dropColumns(Blueprint $table)
6565
*/
6666
public static function getDefaultColumns()
6767
{
68-
return [ self::LFT, self::RGT, self::PARENT_ID ];
68+
return [ static::LFT, static::RGT, static::PARENT_ID ];
6969
}
7070

7171
/**

src/NodeTrait.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ public static function create(array $attributes = [], self $parent = null)
778778
$child->setRelation('parent', $instance);
779779
}
780780

781+
$instance->refreshNode();
782+
781783
return $instance->setRelation('children', $relation);
782784
}
783785

@@ -1006,6 +1008,19 @@ public function isDescendantOf(self $other)
10061008
$this->getLft() < $other->getRgt();
10071009
}
10081010

1011+
/**
1012+
* Get whether a node is itself or a descendant of other node.
1013+
*
1014+
* @param self $other
1015+
*
1016+
* @return bool
1017+
*/
1018+
public function isSelfOrDescendantOf(self $other)
1019+
{
1020+
return $this->getLft() >= $other->getLft() &&
1021+
$this->getLft() < $other->getRgt();
1022+
}
1023+
10091024
/**
10101025
* Get whether the node is immediate children of other node.
10111026
*
@@ -1042,6 +1057,18 @@ public function isAncestorOf(self $other)
10421057
return $other->isDescendantOf($this);
10431058
}
10441059

1060+
/**
1061+
* Get whether the node is itself or an ancestor of other node, including immediate parent.
1062+
*
1063+
* @param self $other
1064+
*
1065+
* @return bool
1066+
*/
1067+
public function isSelfOrAncestorOf(self $other)
1068+
{
1069+
return $other->isSelfOrDescendantOf($this);
1070+
}
1071+
10451072
/**
10461073
* Get whether the node has moved since last save.
10471074
*

0 commit comments

Comments
 (0)