HasNode
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
Bootstrap node events.
Set an action.
Call pending action.
Determine whether the model uses soft deletes.
Apply a raw node action.
Resolve the deferred parent and append the node to it.
Make a root node.
Save the node as a root without moving an existing root.
Get the lower bound.
Append or prepend a node to the parent.
Append or prepend using a parent already read from the write connection.
Apply the current parent of a sibling without resolving its relation.
Refresh node's crucial attributes.
Prepare a model to participate in a structural mutation.
Apply an authoritative structural snapshot to this model.
Read selected attributes from the exact persisted row.
Get the columns that define structural position.
Get the columns that identify one mutable tree row.
Get query for descendants of the node.
Get query for siblings of the node.
Get the relation for the node siblings and the node itself.
Get the node siblings and the node itself.
Get query for siblings after the node.
Get query for siblings before the node.
Get query for nodes after current node.
Get query for nodes before current node in reversed order.
Get query ancestors of the node.
Save node as root.
Prepare the node for insertion as a child.
Prepare the node for insertion beside another node.
Set raw structural values.
Move node up given amount of positions.
Move node down given amount of positions.
Insert node at specific position.
Move a node to the new position.
Insert new node at specified position.
Update the tree when the node is removed physically.
Determine whether descendant model events should be fired during deletion.
Get the descendant deletion chunk size.
Delete descendants through their model lifecycle in children-first chunks.
Get a new base query that includes deleted nodes.
Get a new query with ordinary visibility and the concrete tree scope.
Apply the concrete tree scope to the query.
Get the attributes that partition nested set trees.
Determine whether every configured scope attribute is loaded.
Ensure an existing model has not changed tree scope.
Ensure a model selects one concrete nested set scope.
Get the normalized scope values for this tree.
Normalize a nested set scope value for SQL and identity comparisons.
Get the stable identity key for this tree scope.
Begin a query for one concrete nested set scope.
Create a new nested set collection.
Get node height (rgt - lft + 1).
Get number of descendant nodes.
Set the value of model's parent id key.
Get whether node is root.
Determine whether the node is a leaf.
Get the lft key name.
Get the rgt key name.
Get the parent id key name.
Get the depth column name.
Get the value of the model's lft key.
Get the value of the model's rgt key.
Get the value of the model's parent id key.
Get the node depth.
Returns node that is next to current node without constraining to siblings.
Returns node that is before current node without constraining to siblings.
Get the node's ancestors.
Get the node's descendants.
Get the node's siblings.
Get siblings after the node.
Get siblings before the node.
Get the next sibling.
Get the previous sibling.
Get whether the node is an ancestor of other node, including immediate parent.
Get whether the node is itself or an ancestor of other node, including immediate parent.
Get whether the node has moved since last save.
Get whether user is intended to delete the model from database entirely.
Get the node bounds.
Set the parent key.
Mark the stored bounds as dirty.
Forget relations derived from the node's structural position.
Reject structural targets that are already known to be unusable.
Ensure that this node has loaded bounds.
Ensure that this node has loaded parentage.
Ensure that this node has loaded scope attributes.
Details
at line 51
QueryBuilder
newEloquentBuilder(Builder $query)
Create a new Eloquent query builder for the model.
at line 77
static void
bootHasNode()
Bootstrap node events.
at line 115
protected HasNode
setNodeAction(string $action, mixed ...$args)
Set an action.
at line 125
protected void
callPendingActions()
Call pending action.
at line 159
static bool
usesSoftDelete()
Determine whether the model uses soft deletes.
at line 167
protected bool
actionRaw()
Apply a raw node action.
at line 175
protected bool
actionAppendToParentId(int|string $parentId)
Resolve the deferred parent and append the node to it.
at line 191
protected bool
actionRoot()
Make a root node.
at line 212
protected bool
actionSaveAsRoot()
Save the node as a root without moving an existing root.
at line 222
protected int
getLowerBound()
Get the lower bound.
at line 232
protected bool
actionAppendOrPrepend(HasNode $parent, bool $prepend = false)
Append or prepend a node to the parent.
at line 242
protected bool
actionAppendOrPrependPrepared(HasNode $parent, bool $prepend = false)
Append or prepend using a parent already read from the write connection.
at line 277
protected HasNode
setParentFromSibling(HasNode $node)
Apply the current parent of a sibling without resolving its relation.
at line 294
protected bool
actionBeforeOrAfter(HasNode $node, bool $after = false)
Insert node before or after another node.
at line 313
void
refreshNode()
Refresh node's crucial attributes.
at line 327
void
prepareForNestedSetMutation(array $extraColumns = [])
Prepare a model to participate in a structural mutation.
at line 350
protected void
applyPersistedNodeAttributes(array $attributes)
Apply an authoritative structural snapshot to this model.
at line 360
protected array
getPersistedNodeAttributes(array $columns)
Read selected attributes from the exact persisted row.
at line 382
protected array
getStructuralColumns()
Get the columns that define structural position.
at line 396
protected array
getMutationIdentityColumns()
Get the columns that identify one mutable tree row.
at line 408
BelongsTo
parent()
Relation to the parent.
at line 417
HasMany
children()
Relation to children.
at line 426
DescendantsRelation
descendants()
Get query for descendants of the node.
at line 434
SiblingsRelation
siblings()
Get query for siblings of the node.
at line 442
SiblingsRelation
siblingsAndSelf()
Get the relation for the node siblings and the node itself.
at line 452
Collection
getSiblingsAndSelf(array $columns = ['*'])
Get the node siblings and the node itself.
at line 460
QueryBuilder
nextSiblings()
Get query for siblings after the node.
at line 475
QueryBuilder
prevSiblings()
Get query for siblings before the node.
at line 490
QueryBuilder
nextNodes()
Get query for nodes after current node.
at line 506
QueryBuilder
prevNodes()
Get query for nodes before current node in reversed order.
at line 522
AncestorsRelation
ancestors()
Get query ancestors of the node.
at line 530
HasNode
makeRoot()
Make this node a root node.
at line 540
bool
saveAsRoot()
Save node as root.
at line 548
bool
appendNode(HasNode $node)
Append and save a node.
at line 556
bool
prependNode(HasNode $node)
Prepend and save a node.
at line 580
HasNode
appendOrPrependTo(HasNode $parent, bool $prepend = false)
Prepare the node for insertion as a child.
at line 612
HasNode
beforeOrAfterNode(HasNode $node, bool $after = false)
Prepare the node for insertion beside another node.
at line 628
bool
insertAfterNode(HasNode $node)
Insert self after a node and save.
at line 642
bool
insertBeforeNode(HasNode $node)
Insert self before a node and save.
at line 657
HasNode
rawNode(int $lft, int $rgt, int|string|null $parentId, int|null $depth)
Set raw structural values.
at line 674
bool
up(int $amount = 1)
Move node up given amount of positions.
at line 698
bool
down(int $amount = 1)
Move node down given amount of positions.
at line 722
protected bool
insertAt(int $position, int|null $targetDepth = null)
Insert node at specific position.
at line 732
protected bool
moveNode(int $position, int|null $targetDepth = null)
Move a node to the new position.
at line 779
protected bool
insertNode(int $position, int|null $targetDepth = null)
Insert new node at specified position.
at line 798
protected void
deleteDescendants()
Update the tree when the node is removed physically.
at line 831
protected bool
shouldFireDescendantEvents()
Determine whether descendant model events should be fired during deletion.
at line 839
protected int
getDescendantDeleteChunkSize()
Get the descendant deletion chunk size.
at line 847
protected void
deleteDescendantsWithEvents(bool $forceDelete)
Delete descendants through their model lifecycle in children-first chunks.
at line 899
protected void
restoreDescendants(DateTimeInterface|int|string $deletedAt)
Restore the descendants.
at line 909
QueryBuilder
newNestedSetQuery(string|null $table = null)
Get a new base query that includes deleted nodes.
at line 919
QueryBuilder
newScopedQuery(string|null $table = null)
Get a new query with ordinary visibility and the concrete tree scope.
at line 932
Builder|Builder
applyNestedSetScope(Builder|Builder $query, string|null $table = null)
Apply the concrete tree scope to the query.
at line 960
protected array
getScopeAttributes()
Get the attributes that partition nested set trees.
at line 968
bool
hasCompleteNestedSetScope()
Determine whether every configured scope attribute is loaded.
at line 982
protected void
ensureNestedSetScopeIsUnchanged(array|null $persisted = null)
Ensure an existing model has not changed tree scope.
at line 1026
protected void
ensureConcreteNestedSetScope(string $operation)
Ensure a model selects one concrete nested set scope.
at line 1045
array
getNestedSetScope()
Get the normalized scope values for this tree.
at line 1062
protected int|string|null
normalizeNestedSetScopeValue(string $attribute, mixed $value)
Normalize a nested set scope value for SQL and identity comparisons.
at line 1087
string
getNestedSetScopeKey()
Get the stable identity key for this tree scope.
at line 1107
static QueryBuilder
scoped(array $attributes)
Begin a query for one concrete nested set scope.
at line 1121
Collection
newCollection(array $models = [])
Create a new nested set collection.
at line 1129
static HasNode
create(array $attributes = [], HasNode|null $parent = null)
Use children key on $attributes to create child nodes.
at line 1162
int
getNodeHeight()
Get node height (rgt - lft + 1).
at line 1176
int
getDescendantCount()
Get number of descendant nodes.
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.
at line 1211
bool
isRoot()
Get whether node is root.
at line 1220
bool
isLeaf()
Determine whether the node is a leaf.
at line 1231
string
getLftName()
Get the lft key name.
at line 1239
string
getRgtName()
Get the rgt key name.
at line 1247
string
getParentIdName()
Get the parent id key name.
at line 1255
string
getDepthName()
Get the depth column name.
at line 1263
int|null
getLft()
Get the value of the model's lft key.
at line 1273
int|null
getRgt()
Get the value of the model's rgt key.
at line 1283
int|string|null
getParentId()
Get the value of the model's parent id key.
at line 1291
int|null
getDepth()
Get the node depth.
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.
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.
at line 1325
Collection
getAncestors(array $columns = ['*'])
Get the node's ancestors.
at line 1335
Collection
getDescendants(array $columns = ['*'])
Get the node's descendants.
at line 1345
Collection
getSiblings(array $columns = ['*'])
Get the node's siblings.
at line 1355
Collection
getNextSiblings(array $columns = ['*'])
Get siblings after the node.
at line 1365
Collection
getPrevSiblings(array $columns = ['*'])
Get siblings before the node.
at line 1375
Model|null
getNextSibling(array $columns = ['*'])
Get the next sibling.
at line 1385
Model|null
getPrevSibling(array $columns = ['*'])
Get the previous sibling.
at line 1393
bool
isDescendantOf(HasNode $other)
Get whether a node is a descendant of other node.
at line 1413
bool
isSelfOrDescendantOf(HasNode $other)
Get whether a node is itself or a descendant of other node.
at line 1437
bool
isChildOf(HasNode $other)
Get whether the node is immediate children of other node.
at line 1453
bool
isSiblingOf(HasNode $other)
Get whether the node is a sibling of another node.
at line 1476
bool
isAncestorOf(HasNode $other)
Get whether the node is an ancestor of other node, including immediate parent.
at line 1484
bool
isSelfOrAncestorOf(HasNode $other)
Get whether the node is itself or an ancestor of other node, including immediate parent.
at line 1492
bool
hasMoved()
Get whether the node has moved since last save.
at line 1500
protected bool
hasForceDeleting()
Get whether user is intended to delete the model from database entirely.
at line 1510
array
getBounds()
Get the node bounds.
at line 1518
HasNode
setLft(int|null $value)
Set the left bound.
at line 1528
HasNode
setRgt(int|null $value)
Set the right bound.
at line 1538
HasNode
setParentId(int|string|null $value)
Set the parent key.
at line 1548
HasNode
setDepth(int|null $value)
Set the node depth.
at line 1558
protected HasNode
dirtyBounds()
Mark the stored bounds as dirty.
at line 1569
protected void
unsetNestedSetRelations()
Forget relations derived from the node's structural position.
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.
at line 1617
protected HasNode
assertNotDescendant(HasNode $node)
Assert that a node is not this node's descendant.
at line 1629
protected HasNode
ensureNodeInTree(HasNode $node)
Ensure that a node has persisted tree bounds.
at line 1641
protected void
ensureBoundsLoaded()
Ensure that this node has loaded bounds.
at line 1654
protected void
ensureParentageLoaded()
Ensure that this node has loaded parentage.
at line 1667
protected void
ensureScopeLoaded()
Ensure that this node has loaded scope attributes.
at line 1683
protected HasNode
ensureSameTree(HasNode $node)
Ensure that a node belongs to the same nested set tree.
at line 1695
protected bool
isSameScope(HasNode $node)
Determine whether a node belongs to the same concrete scope.
at line 1705
protected bool
isSameTree(HasNode $node)
Determine whether the models address the same nested set tree.
at line 1714
protected bool
isSameNode(HasNode $node)
Determine whether the models address the same persisted row.
at line 1734
HasNode
replicate(array|null $except = null)
Clone the node without structural attributes.