trait HasNode

Properties

protected array $pending

Pending operations.

protected bool $moved

Whether the node has moved since last save.

protected bool $deletingAsDescendant

Whether the node is being deleted by an evented descendant cascade.

null|int|string $parent_id
?int $depth
?static $parent

Methods

newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

static void
bootHasNode()

Bootstrap node events.

setNodeAction(string $action, mixed ...$args)

Set an action.

void
callPendingActions()

Call pending action.

static bool
usesSoftDelete()

Determine whether the model uses soft deletes.

bool
actionRaw()

Apply a raw node action.

bool
actionAppendToParentId(int|string $parentId)

Resolve the deferred parent and append the node to it.

bool
actionRoot()

Make a root node.

bool
actionSaveAsRoot()

Save the node as a root without moving an existing root.

int
getLowerBound()

Get the lower bound.

bool
actionAppendOrPrepend(HasNode $parent, bool $prepend = false)

Append or prepend a node to the parent.

bool
actionAppendOrPrependPrepared(HasNode $parent, bool $prepend = false)

Append or prepend using a parent already read from the write connection.

setParent(Model|null $value)

Apply parent model.

setParentFromSibling(HasNode $node)

Apply the current parent of a sibling without resolving its relation.

bool
actionBeforeOrAfter(HasNode $node, bool $after = false)

Insert node before or after another node.

void
refreshNode()

Refresh node's crucial attributes.

void
prepareForNestedSetMutation(array $extraColumns = [])

Prepare a model to participate in a structural mutation.

void
applyPersistedNodeAttributes(array $attributes)

Apply an authoritative structural snapshot to this model.

array
getPersistedNodeAttributes(array $columns)

Read selected attributes from the exact persisted row.

array
getStructuralColumns()

Get the columns that define structural position.

array
getMutationIdentityColumns()

Get the columns that identify one mutable tree row.

parent()

Relation to the parent.

children()

Relation to children.

descendants()

Get query for descendants of the node.

siblings()

Get query for siblings of the node.

siblingsAndSelf()

Get the relation for the node siblings and the node itself.

getSiblingsAndSelf(array $columns = ['*'])

Get the node siblings and the node itself.

nextSiblings()

Get query for siblings after the node.

prevSiblings()

Get query for siblings before the node.

nextNodes()

Get query for nodes after current node.

prevNodes()

Get query for nodes before current node in reversed order.

ancestors()

Get query ancestors of the node.

makeRoot()

Make this node a root node.

bool
saveAsRoot()

Save node as root.

bool
appendNode(HasNode $node)

Append and save a node.

bool
prependNode(HasNode $node)

Prepend and save a node.

appendToNode(HasNode $parent)

Append a node to the new parent.

prependToNode(HasNode $parent)

Prepend a node to the new parent.

appendOrPrependTo(HasNode $parent, bool $prepend = false)

Prepare the node for insertion as a child.

afterNode(HasNode $node)

Insert self after a node.

beforeNode(HasNode $node)

Insert self before node.

beforeOrAfterNode(HasNode $node, bool $after = false)

Prepare the node for insertion beside another node.

bool
insertAfterNode(HasNode $node)

Insert self after a node and save.

bool
insertBeforeNode(HasNode $node)

Insert self before a node and save.

rawNode(int $lft, int $rgt, int|string|null $parentId, int|null $depth)

Set raw structural values.

bool
up(int $amount = 1)

Move node up given amount of positions.

bool
down(int $amount = 1)

Move node down given amount of positions.

bool
insertAt(int $position, int|null $targetDepth = null)

Insert node at specific position.

bool
moveNode(int $position, int|null $targetDepth = null)

Move a node to the new position.

bool
insertNode(int $position, int|null $targetDepth = null)

Insert new node at specified position.

void
deleteDescendants()

Update the tree when the node is removed physically.

bool
shouldFireDescendantEvents()

Determine whether descendant model events should be fired during deletion.

int
getDescendantDeleteChunkSize()

Get the descendant deletion chunk size.

void
deleteDescendantsWithEvents(bool $forceDelete)

Delete descendants through their model lifecycle in children-first chunks.

void
restoreDescendants(DateTimeInterface|int|string $deletedAt)

Restore the descendants.

newNestedSetQuery(string|null $table = null)

Get a new base query that includes deleted nodes.

newScopedQuery(string|null $table = null)

Get a new query with ordinary visibility and the concrete tree scope.

applyNestedSetScope(Builder|Builder $query, string|null $table = null)

Apply the concrete tree scope to the query.

array
getScopeAttributes()

Get the attributes that partition nested set trees.

bool
hasCompleteNestedSetScope()

Determine whether every configured scope attribute is loaded.

void
ensureNestedSetScopeIsUnchanged(array|null $persisted = null)

Ensure an existing model has not changed tree scope.

void
ensureConcreteNestedSetScope(string $operation)

Ensure a model selects one concrete nested set scope.

array
getNestedSetScope()

Get the normalized scope values for this tree.

int|string|null
normalizeNestedSetScopeValue(string $attribute, mixed $value)

Normalize a nested set scope value for SQL and identity comparisons.

string
getNestedSetScopeKey()

Get the stable identity key for this tree scope.

static QueryBuilder
scoped(array $attributes)

Begin a query for one concrete nested set scope.

newCollection(array $models = [])

Create a new nested set collection.

static HasNode
create(array $attributes = [], HasNode|null $parent = null)

Use children key on $attributes to create child nodes.

int
getNodeHeight()

Get node height (rgt - lft + 1).

int
getDescendantCount()

Get number of descendant nodes.

void
setParentIdAttribute(int|string|null $value)

Set the value of model's parent id key.

bool
isRoot()

Get whether node is root.

bool
isLeaf()

Determine whether the node is a leaf.

string
getLftName()

Get the lft key name.

string
getRgtName()

Get the rgt key name.

string
getParentIdName()

Get the parent id key name.

string
getDepthName()

Get the depth column name.

int|null
getLft()

Get the value of the model's lft key.

int|null
getRgt()

Get the value of the model's rgt key.

int|string|null
getParentId()

Get the value of the model's parent id key.

int|null
getDepth()

Get the node depth.

Model|null
getNextNode(array $columns = ['*'])

Returns node that is next to current node without constraining to siblings.

Model|null
getPrevNode(array $columns = ['*'])

Returns node that is before current node without constraining to siblings.

getAncestors(array $columns = ['*'])

Get the node's ancestors.

getDescendants(array $columns = ['*'])

Get the node's descendants.

getSiblings(array $columns = ['*'])

Get the node's siblings.

getNextSiblings(array $columns = ['*'])

Get siblings after the node.

getPrevSiblings(array $columns = ['*'])

Get siblings before the node.

Model|null
getNextSibling(array $columns = ['*'])

Get the next sibling.

Model|null
getPrevSibling(array $columns = ['*'])

Get the previous sibling.

bool
isDescendantOf(HasNode $other)

Get whether a node is a descendant of other node.

bool
isSelfOrDescendantOf(HasNode $other)

Get whether a node is itself or a descendant of other node.

bool
isChildOf(HasNode $other)

Get whether the node is immediate children of other node.

bool
isSiblingOf(HasNode $other)

Get whether the node is a sibling of another node.

bool
isAncestorOf(HasNode $other)

Get whether the node is an ancestor of other node, including immediate parent.

bool
isSelfOrAncestorOf(HasNode $other)

Get whether the node is itself or an ancestor of other node, including immediate parent.

bool
hasMoved()

Get whether the node has moved since last save.

bool
hasForceDeleting()

Get whether user is intended to delete the model from database entirely.

array
getBounds()

Get the node bounds.

setLft(int|null $value)

Set the left bound.

setRgt(int|null $value)

Set the right bound.

setParentId(int|string|null $value)

Set the parent key.

setDepth(int|null $value)

Set the node depth.

dirtyBounds()

Mark the stored bounds as dirty.

void
unsetNestedSetRelations()

Forget relations derived from the node's structural position.

void
ensureLoadedStructuralTargetIsValid(HasNode $node)

Reject structural targets that are already known to be unusable.

assertNotDescendant(HasNode $node)

Assert that a node is not this node's descendant.

ensureNodeInTree(HasNode $node)

Ensure that a node has persisted tree bounds.

void
ensureBoundsLoaded()

Ensure that this node has loaded bounds.

void
ensureParentageLoaded()

Ensure that this node has loaded parentage.

void
ensureScopeLoaded()

Ensure that this node has loaded scope attributes.

ensureSameTree(HasNode $node)

Ensure that a node belongs to the same nested set tree.

bool
isSameScope(HasNode $node)

Determine whether a node belongs to the same concrete scope.

bool
isSameTree(HasNode $node)

Determine whether the models address the same nested set tree.

bool
isSameNode(HasNode $node)

Determine whether the models address the same persisted row.

replicate(array|null $except = null)

Clone the node without structural attributes.

Details

at line 51
QueryBuilder newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

Parameters

Builder $query

Return Value

QueryBuilder

at line 77
static void bootHasNode()

Bootstrap node events.

Return Value

void

at line 115
protected HasNode setNodeAction(string $action, mixed ...$args)

Set an action.

Parameters

string $action
mixed ...$args

Return Value

HasNode

at line 125
protected void callPendingActions()

Call pending action.

Return Value

void

at line 159
static bool usesSoftDelete()

Determine whether the model uses soft deletes.

Return Value

bool

at line 167
protected bool actionRaw()

Apply a raw node action.

Return Value

bool

at line 175
protected bool actionAppendToParentId(int|string $parentId)

Resolve the deferred parent and append the node to it.

Parameters

int|string $parentId

Return Value

bool

at line 191
protected bool actionRoot()

Make a root node.

Return Value

bool

at line 212
protected bool actionSaveAsRoot()

Save the node as a root without moving an existing root.

Return Value

bool

at line 222
protected int getLowerBound()

Get the lower bound.

Return Value

int

at line 232
protected bool actionAppendOrPrepend(HasNode $parent, bool $prepend = false)

Append or prepend a node to the parent.

Parameters

HasNode $parent
bool $prepend

Return Value

bool

at line 242
protected bool actionAppendOrPrependPrepared(HasNode $parent, bool $prepend = false)

Append or prepend using a parent already read from the write connection.

Parameters

HasNode $parent
bool $prepend

Return Value

bool

at line 266
protected HasNode setParent(Model|null $value)

Apply parent model.

Parameters

Model|null $value

Return Value

HasNode

at line 277
protected HasNode setParentFromSibling(HasNode $node)

Apply the current parent of a sibling without resolving its relation.

Parameters

HasNode $node

Return Value

HasNode

at line 294
protected bool actionBeforeOrAfter(HasNode $node, bool $after = false)

Insert node before or after another node.

Parameters

HasNode $node
bool $after

Return Value

bool

at line 313
void refreshNode()

Refresh node's crucial attributes.

Return Value

void

at line 327
void prepareForNestedSetMutation(array $extraColumns = [])

Prepare a model to participate in a structural mutation.

Parameters

array $extraColumns

Return Value

void

at line 350
protected void applyPersistedNodeAttributes(array $attributes)

Apply an authoritative structural snapshot to this model.

Parameters

array $attributes

Return Value

void

at line 360
protected array getPersistedNodeAttributes(array $columns)

Read selected attributes from the exact persisted row.

Parameters

array $columns

Return Value

array

at line 382
protected array getStructuralColumns()

Get the columns that define structural position.

Return Value

array

at line 396
protected array getMutationIdentityColumns()

Get the columns that identify one mutable tree row.

Return Value

array

at line 408
BelongsTo parent()

Relation to the parent.

Return Value

BelongsTo

at line 417
HasMany children()

Relation to children.

Return Value

HasMany

at line 426
DescendantsRelation descendants()

Get query for descendants of the node.

Return Value

DescendantsRelation

at line 434
SiblingsRelation siblings()

Get query for siblings of the node.

Return Value

SiblingsRelation

at line 442
SiblingsRelation siblingsAndSelf()

Get the relation for the node siblings and the node itself.

Return Value

SiblingsRelation

at line 452
Collection getSiblingsAndSelf(array $columns = ['*'])

Get the node siblings and the node itself.

Parameters

array $columns

Return Value

Collection

at line 460
QueryBuilder nextSiblings()

Get query for siblings after the node.

Return Value

QueryBuilder

at line 475
QueryBuilder prevSiblings()

Get query for siblings before the node.

Return Value

QueryBuilder

at line 490
QueryBuilder nextNodes()

Get query for nodes after current node.

Return Value

QueryBuilder

at line 506
QueryBuilder prevNodes()

Get query for nodes before current node in reversed order.

Return Value

QueryBuilder

at line 522
AncestorsRelation ancestors()

Get query ancestors of the node.

Return Value

AncestorsRelation

at line 530
HasNode makeRoot()

Make this node a root node.

Return Value

HasNode

at line 540
bool saveAsRoot()

Save node as root.

Return Value

bool

at line 548
bool appendNode(HasNode $node)

Append and save a node.

Parameters

HasNode $node

Return Value

bool

at line 556
bool prependNode(HasNode $node)

Prepend and save a node.

Parameters

HasNode $node

Return Value

bool

at line 564
HasNode appendToNode(HasNode $parent)

Append a node to the new parent.

Parameters

HasNode $parent

Return Value

HasNode

at line 572
HasNode prependToNode(HasNode $parent)

Prepend a node to the new parent.

Parameters

HasNode $parent

Return Value

HasNode

at line 580
HasNode appendOrPrependTo(HasNode $parent, bool $prepend = false)

Prepare the node for insertion as a child.

Parameters

HasNode $parent
bool $prepend

Return Value

HasNode

at line 596
HasNode afterNode(HasNode $node)

Insert self after a node.

Parameters

HasNode $node

Return Value

HasNode

at line 604
HasNode beforeNode(HasNode $node)

Insert self before node.

Parameters

HasNode $node

Return Value

HasNode

at line 612
HasNode beforeOrAfterNode(HasNode $node, bool $after = false)

Prepare the node for insertion beside another node.

Parameters

HasNode $node
bool $after

Return Value

HasNode

at line 628
bool insertAfterNode(HasNode $node)

Insert self after a node and save.

Parameters

HasNode $node

Return Value

bool

at line 642
bool insertBeforeNode(HasNode $node)

Insert self before a node and save.

Parameters

HasNode $node

Return Value

bool

at line 657
HasNode rawNode(int $lft, int $rgt, int|string|null $parentId, int|null $depth)

Set raw structural values.

Parameters

int $lft
int $rgt
int|string|null $parentId
int|null $depth

Return Value

HasNode

at line 674
bool up(int $amount = 1)

Move node up given amount of positions.

Parameters

int $amount

Return Value

bool

at line 698
bool down(int $amount = 1)

Move node down given amount of positions.

Parameters

int $amount

Return Value

bool

at line 722
protected bool insertAt(int $position, int|null $targetDepth = null)

Insert node at specific position.

Parameters

int $position
int|null $targetDepth

Return Value

bool

at line 732
protected bool moveNode(int $position, int|null $targetDepth = null)

Move a node to the new position.

Parameters

int $position
int|null $targetDepth

Return Value

bool

at line 779
protected bool insertNode(int $position, int|null $targetDepth = null)

Insert new node at specified position.

Parameters

int $position
int|null $targetDepth

Return Value

bool

at line 798
protected void deleteDescendants()

Update the tree when the node is removed physically.

Return Value

void

at line 831
protected bool shouldFireDescendantEvents()

Determine whether descendant model events should be fired during deletion.

Return Value

bool

at line 839
protected int getDescendantDeleteChunkSize()

Get the descendant deletion chunk size.

Return Value

int

at line 847
protected void deleteDescendantsWithEvents(bool $forceDelete)

Delete descendants through their model lifecycle in children-first chunks.

Parameters

bool $forceDelete

Return Value

void

at line 899
protected void restoreDescendants(DateTimeInterface|int|string $deletedAt)

Restore the descendants.

Parameters

DateTimeInterface|int|string $deletedAt

Return Value

void

at line 909
QueryBuilder newNestedSetQuery(string|null $table = null)

Get a new base query that includes deleted nodes.

Parameters

string|null $table

Return Value

QueryBuilder

at line 919
QueryBuilder newScopedQuery(string|null $table = null)

Get a new query with ordinary visibility and the concrete tree scope.

Parameters

string|null $table

Return Value

QueryBuilder

at line 932
Builder|Builder applyNestedSetScope(Builder|Builder $query, string|null $table = null)

Apply the concrete tree scope to the query.

Parameters

Builder|Builder $query
string|null $table

Return Value

Builder|Builder

at line 960
protected array getScopeAttributes()

Get the attributes that partition nested set trees.

Return Value

array

at line 968
bool hasCompleteNestedSetScope()

Determine whether every configured scope attribute is loaded.

Return Value

bool

at line 982
protected void ensureNestedSetScopeIsUnchanged(array|null $persisted = null)

Ensure an existing model has not changed tree scope.

Parameters

array|null $persisted

Return Value

void

at line 1026
protected void ensureConcreteNestedSetScope(string $operation)

Ensure a model selects one concrete nested set scope.

Parameters

string $operation

Return Value

void

at line 1045
array getNestedSetScope()

Get the normalized scope values for this tree.

Return Value

array

at line 1062
protected int|string|null normalizeNestedSetScopeValue(string $attribute, mixed $value)

Normalize a nested set scope value for SQL and identity comparisons.

Parameters

string $attribute
mixed $value

Return Value

int|string|null

at line 1087
string getNestedSetScopeKey()

Get the stable identity key for this tree scope.

Return Value

string

at line 1107
static QueryBuilder scoped(array $attributes)

Begin a query for one concrete nested set scope.

Parameters

array $attributes

Return Value

QueryBuilder

at line 1121
Collection newCollection(array $models = [])

Create a new nested set collection.

Parameters

array $models

Return Value

Collection

at line 1129
static HasNode create(array $attributes = [], HasNode|null $parent = null)

Use children key on $attributes to create child nodes.

Parameters

array $attributes
HasNode|null $parent

Return Value

HasNode

at line 1162
int getNodeHeight()

Get node height (rgt - lft + 1).

Return Value

int

at line 1176
int getDescendantCount()

Get number of descendant nodes.

Return Value

int

at line 1185
void setParentIdAttribute(int|string|null $value)

Set the value of model's parent id key.

Behind the scenes node is appended to found parent node.

Parameters

int|string|null $value

Return Value

void

at line 1211
bool isRoot()

Get whether node is root.

Return Value

bool

at line 1220
bool isLeaf()

Determine whether the node is a leaf.

Return Value

bool

at line 1231
string getLftName()

Get the lft key name.

Return Value

string

at line 1239
string getRgtName()

Get the rgt key name.

Return Value

string

at line 1247
string getParentIdName()

Get the parent id key name.

Return Value

string

at line 1255
string getDepthName()

Get the depth column name.

Return Value

string

at line 1263
int|null getLft()

Get the value of the model's lft key.

Return Value

int|null

at line 1273
int|null getRgt()

Get the value of the model's rgt key.

Return Value

int|null

at line 1283
int|string|null getParentId()

Get the value of the model's parent id key.

Return Value

int|string|null

at line 1291
int|null getDepth()

Get the node depth.

Return Value

int|null

at line 1304
Model|null getNextNode(array $columns = ['*'])

Returns node that is next to current node without constraining to siblings.

This can be either a next sibling or a next sibling of the parent node.

Parameters

array $columns

Return Value

Model|null

at line 1315
Model|null getPrevNode(array $columns = ['*'])

Returns node that is before current node without constraining to siblings.

This can be either a prev sibling or parent node.

Parameters

array $columns

Return Value

Model|null

at line 1325
Collection getAncestors(array $columns = ['*'])

Get the node's ancestors.

Parameters

array $columns

Return Value

Collection

at line 1335
Collection getDescendants(array $columns = ['*'])

Get the node's descendants.

Parameters

array $columns

Return Value

Collection

at line 1345
Collection getSiblings(array $columns = ['*'])

Get the node's siblings.

Parameters

array $columns

Return Value

Collection

at line 1355
Collection getNextSiblings(array $columns = ['*'])

Get siblings after the node.

Parameters

array $columns

Return Value

Collection

at line 1365
Collection getPrevSiblings(array $columns = ['*'])

Get siblings before the node.

Parameters

array $columns

Return Value

Collection

at line 1375
Model|null getNextSibling(array $columns = ['*'])

Get the next sibling.

Parameters

array $columns

Return Value

Model|null

at line 1385
Model|null getPrevSibling(array $columns = ['*'])

Get the previous sibling.

Parameters

array $columns

Return Value

Model|null

at line 1393
bool isDescendantOf(HasNode $other)

Get whether a node is a descendant of other node.

Parameters

HasNode $other

Return Value

bool

at line 1413
bool isSelfOrDescendantOf(HasNode $other)

Get whether a node is itself or a descendant of other node.

Parameters

HasNode $other

Return Value

bool

at line 1437
bool isChildOf(HasNode $other)

Get whether the node is immediate children of other node.

Parameters

HasNode $other

Return Value

bool

at line 1453
bool isSiblingOf(HasNode $other)

Get whether the node is a sibling of another node.

Parameters

HasNode $other

Return Value

bool

at line 1476
bool isAncestorOf(HasNode $other)

Get whether the node is an ancestor of other node, including immediate parent.

Parameters

HasNode $other

Return Value

bool

at line 1484
bool isSelfOrAncestorOf(HasNode $other)

Get whether the node is itself or an ancestor of other node, including immediate parent.

Parameters

HasNode $other

Return Value

bool

at line 1492
bool hasMoved()

Get whether the node has moved since last save.

Return Value

bool

at line 1500
protected bool hasForceDeleting()

Get whether user is intended to delete the model from database entirely.

Return Value

bool

at line 1510
array getBounds()

Get the node bounds.

Return Value

array

at line 1518
HasNode setLft(int|null $value)

Set the left bound.

Parameters

int|null $value

Return Value

HasNode

at line 1528
HasNode setRgt(int|null $value)

Set the right bound.

Parameters

int|null $value

Return Value

HasNode

at line 1538
HasNode setParentId(int|string|null $value)

Set the parent key.

Parameters

int|string|null $value

Return Value

HasNode

at line 1548
HasNode setDepth(int|null $value)

Set the node depth.

Parameters

int|null $value

Return Value

HasNode

at line 1558
protected HasNode dirtyBounds()

Mark the stored bounds as dirty.

Return Value

HasNode

at line 1569
protected void unsetNestedSetRelations()

Forget relations derived from the node's structural position.

Return Value

void

at line 1589
protected void ensureLoadedStructuralTargetIsValid(HasNode $node)

Reject structural targets that are already known to be unusable.

Partial models are deliberately allowed here. The save boundary reloads every participant from the write connection before changing the tree.

Parameters

HasNode $node

Return Value

void

at line 1617
protected HasNode assertNotDescendant(HasNode $node)

Assert that a node is not this node's descendant.

Parameters

HasNode $node

Return Value

HasNode

at line 1629
protected HasNode ensureNodeInTree(HasNode $node)

Ensure that a node has persisted tree bounds.

Parameters

HasNode $node

Return Value

HasNode

at line 1641
protected void ensureBoundsLoaded()

Ensure that this node has loaded bounds.

Return Value

void

at line 1654
protected void ensureParentageLoaded()

Ensure that this node has loaded parentage.

Return Value

void

at line 1667
protected void ensureScopeLoaded()

Ensure that this node has loaded scope attributes.

Return Value

void

at line 1683
protected HasNode ensureSameTree(HasNode $node)

Ensure that a node belongs to the same nested set tree.

Parameters

HasNode $node

Return Value

HasNode

at line 1695
protected bool isSameScope(HasNode $node)

Determine whether a node belongs to the same concrete scope.

Parameters

HasNode $node

Return Value

bool

at line 1705
protected bool isSameTree(HasNode $node)

Determine whether the models address the same nested set tree.

Parameters

HasNode $node

Return Value

bool

at line 1714
protected bool isSameNode(HasNode $node)

Determine whether the models address the same persisted row.

Parameters

HasNode $node

Return Value

bool

at line 1734
HasNode replicate(array|null $except = null)

Clone the node without structural attributes.

Parameters

array|null $except

Return Value

HasNode