HasNode
trait HasNode
Traits
Properties
| protected array | $pending | Pending operations. |
|
| protected bool | $moved | Whether the node has moved since last save. |
|
| protected bool | $cascadingAsDescendant | Whether the node is being deleted or restored by an ancestor's evented cascade. |
|
| null|int|string | $parent_id | ||
| ?int | $depth | ||
| ?static | $parent |
Methods
Get a new query builder that doesn't have any global scopes or eager loading.
Get a new query builder with no relationships loaded.
Get a new query builder that doesn't have any global scopes.
Get a new query to restore one or more models by their queueable IDs.
Begin querying the model on a given connection.
Begin querying the model on the write connection.
Begin querying a model with eager loading.
Fire the given event for the model, keeping the tree consistent around its observers.
Set an action.
Call pending action.
Save the model to the database.
Save the model to the database, ignoring specific unique constraint conflicts.
Run a save, restoring its consumed action when the save does not complete.
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.
Prepare an existing model for a structural mutation from its persisted row.
Apply an authoritative structural snapshot to this model.
Read selected attributes from the exact persisted row.
Read selected attributes from the exact persisted row, if it still exists.
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.
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.
Delete the node's descendants, including any hidden by ordinary global scopes.
Determine whether descendant model events should be fired during deletion and restoration.
Get the number of descendants loaded per evented deletion or restoration chunk.
Delete descendants through their model lifecycle in children-first chunks.
Change descendants one at a time in bounded chunks ordered by their left bound.
Restore descendants deleted at or after the given stored deletion time.
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.
Return the node that is next to the current node without constraining to siblings.
Return the node that is before the 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.
Assert that a node is neither this node nor one of its descendants.
Ensure that this node has loaded bounds.
Ensure that this node has loaded parentage.
Ensure that this node has loaded scope attributes.
Details
in
HasBuilder at line 20
static Builder
query()
Begin querying the model.
at line 57
QueryBuilder
newEloquentBuilder(Builder $query)
Create a new Eloquent query builder for the model.
in
HasBuilder at line 40
Builder
newQuery()
Get a new query builder for the model's table.
in
HasBuilder at line 50
Builder
newModelQuery()
Get a new query builder that doesn't have any global scopes or eager loading.
in
HasBuilder at line 60
Builder
newQueryWithoutRelationships()
Get a new query builder with no relationships loaded.
in
HasBuilder at line 70
Builder
newQueryWithoutScopes()
Get a new query builder that doesn't have any global scopes.
in
HasBuilder at line 80
Builder
newQueryWithoutScope(Scope|int|string $scope)
Get a new query instance without a given scope.
in
HasBuilder at line 90
Builder
newQueryForRestoration(array|int|string $ids)
Get a new query to restore one or more models by their queueable IDs.
in
HasBuilder at line 100
static Builder
on(UnitEnum|string|null $connection = null)
Begin querying the model on a given connection.
in
HasBuilder at line 110
static Builder
onWriteConnection()
Begin querying the model on the write connection.
in
HasBuilder at line 120
static Builder
with(array|string $relations)
Begin querying a model with eager loading.
at line 89
protected mixed
fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model, keeping the tree consistent around its observers.
Upstream maintains the tree from listeners registered in bootNodeTrait(). A custom $dispatchesEvents result skips those listeners, and listeners cannot act after every deleting observer has allowed a delete, so the maintenance runs here instead.
at line 157
protected HasNode
setNodeAction(string $action, mixed ...$args)
Set an action.
at line 167
protected void
callPendingAction()
Call pending action.
at line 201
bool
save(array $options = [])
Save the model to the database.
at line 209
bool
saveOrIgnore(array $options = [], array|string|null $uniqueBy = null)
Save the model to the database, ignoring specific unique constraint conflicts.
at line 217
protected bool
restorePendingActionUnlessSaved(Closure $save)
Run a save, restoring its consumed action when the save does not complete.
at line 236
static bool
usesSoftDelete()
Determine whether the model uses soft deletes.
at line 244
protected bool
actionRaw()
Apply a raw node action.
at line 252
protected bool
actionAppendToParentId(int|string $parentId)
Resolve the deferred parent and append the node to it.
at line 268
protected bool
actionRoot()
Make a root node.
at line 289
protected bool
actionSaveAsRoot()
Save the node as a root without moving an existing root.
at line 299
protected int
getLowerBound()
Get the lower bound.
at line 309
protected bool
actionAppendOrPrepend(HasNode $parent, bool $prepend = false)
Append or prepend a node to the parent.
at line 319
protected bool
actionAppendOrPrependPrepared(HasNode $parent, bool $prepend = false)
Append or prepend using a parent already read from the write connection.
at line 354
protected HasNode
setParentFromSibling(HasNode $node)
Apply the current parent of a sibling without resolving its relation.
at line 371
protected bool
actionBeforeOrAfter(HasNode $node, bool $after = false)
Insert node before or after another node.
at line 390
void
refreshNode()
Refresh node's crucial attributes.
at line 404
void
prepareForNestedSetMutation(array $extraColumns = [])
Prepare a model to participate in a structural mutation.
at line 424
protected void
prepareFromPersistedAttributes(array $persisted)
Prepare an existing model for a structural mutation from its persisted row.
at line 434
protected void
applyPersistedNodeAttributes(array $attributes)
Apply an authoritative structural snapshot to this model.
at line 444
protected array
getPersistedNodeAttributes(array $columns)
Read selected attributes from the exact persisted row.
at line 453
protected array|null
findPersistedNodeAttributes(array $columns)
Read selected attributes from the exact persisted row, if it still exists.
at line 478
protected array
getStructuralColumns()
Get the columns that define structural position.
at line 492
protected array
getMutationIdentityColumns()
Get the columns that identify one mutable tree row.
at line 506
BelongsTo
parent()
Relation to the parent.
at line 517
HasMany
children()
Relation to children.
at line 528
DescendantsRelation
descendants()
Get query for descendants of the node.
at line 538
SiblingsRelation
siblings()
Get query for siblings of the node.
at line 548
SiblingsRelation
siblingsAndSelf()
Get the relation for the node siblings and the node itself.
at line 558
Collection
getSiblingsAndSelf(array $columns = ['*'])
Get the node siblings and the node itself.
at line 568
QueryBuilder
nextSiblings()
Get query for siblings after the node.
at line 585
QueryBuilder
prevSiblings()
Get query for siblings before the node.
at line 602
QueryBuilder
nextNodes()
Get query for nodes after current node.
at line 620
QueryBuilder
prevNodes()
Get query for nodes before current node.
at line 638
AncestorsRelation
ancestors()
Get query ancestors of the node.
at line 646
HasNode
makeRoot()
Make this node a root node.
at line 656
bool
saveAsRoot()
Save node as root.
at line 664
bool
appendNode(HasNode $node)
Append and save a node.
at line 672
bool
prependNode(HasNode $node)
Prepend and save a node.
at line 696
HasNode
appendOrPrependTo(HasNode $parent, bool $prepend = false)
Prepare the node for insertion as a child.
at line 728
HasNode
beforeOrAfterNode(HasNode $node, bool $after = false)
Prepare the node for insertion beside another node.
at line 744
bool
insertAfterNode(HasNode $node)
Insert self after a node and save.
at line 758
bool
insertBeforeNode(HasNode $node)
Insert self before a node and save.
at line 773
HasNode
rawNode(int $lft, int $rgt, int|string|null $parentId, int|null $depth)
Set raw structural values.
at line 790
bool
up(int $amount = 1)
Move node up given amount of positions.
at line 814
bool
down(int $amount = 1)
Move node down given amount of positions.
at line 838
protected bool
insertAt(int $position, int|null $targetDepth = null)
Insert node at specific position.
at line 848
protected bool
moveNode(int $position, int|null $targetDepth = null)
Move a node to the new position.
at line 897
protected bool
insertNode(int $position, int|null $targetDepth = null)
Insert new node at specified position.
at line 919
protected void
deleteDescendants()
Delete the node's descendants, including any hidden by ordinary global scopes.
Hard deletes run before the node's own row is deleted and soft deletes after it, so descendants are never trashed before the node.
at line 940
protected bool
shouldFireDescendantEvents()
Determine whether descendant model events should be fired during deletion and restoration.
at line 948
protected int
getDescendantChunkSize()
Get the number of descendants loaded per evented deletion or restoration chunk.
at line 956
protected void
deleteDescendantsWithEvents(bool $forceDelete)
Delete descendants through their model lifecycle in children-first chunks.
at line 979
protected void
changeDescendantsWithEvents(QueryBuilder $query, bool $childrenFirst, string $operation, Closure $change)
Change descendants one at a time in bounded chunks ordered by their left bound.
at line 1023
protected void
restoreDescendants(DateTimeInterface|int|string $deletedAt)
Restore descendants deleted at or after the given stored deletion time.
at line 1048
QueryBuilder
newNestedSetQuery(string|null $table = null)
Get a new base query that includes deleted nodes.
at line 1060
QueryBuilder
newScopedQuery(string|null $table = null)
Get a new query with ordinary visibility and the concrete tree scope.
at line 1073
Builder|Builder
applyNestedSetScope(Builder|Builder $query, string|null $table = null)
Apply the concrete tree scope to the query.
at line 1101
protected array
getScopeAttributes()
Get the attributes that partition nested set trees.
at line 1109
bool
hasCompleteNestedSetScope()
Determine whether every configured scope attribute is loaded.
at line 1123
protected void
ensureNestedSetScopeIsUnchanged(array|null $persisted = null)
Ensure an existing model has not changed tree scope.
at line 1167
protected void
ensureConcreteNestedSetScope(string $operation)
Ensure a model selects one concrete nested set scope.
at line 1186
array
getNestedSetScope()
Get the normalized scope values for this tree.
at line 1203
protected int|string|null
normalizeNestedSetScopeValue(string $attribute, mixed $value)
Normalize a nested set scope value for SQL and identity comparisons.
at line 1224
string
getNestedSetScopeKey()
Get the stable identity key for this tree scope.
at line 1246
static QueryBuilder
scoped(array $attributes)
Begin a query for one concrete nested set scope.
at line 1261
Collection
newCollection(array $models = [])
Create a new nested set collection.
at line 1269
static HasNode
create(array $attributes = [], HasNode|null $parent = null)
Use children key on $attributes to create child nodes.
at line 1305
int
getNodeHeight()
Get node height (rgt - lft + 1).
at line 1319
int
getDescendantCount()
Get number of descendant nodes.
at line 1328
HasNode
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 1354
bool
isRoot()
Get whether node is root.
at line 1363
bool
isLeaf()
Determine whether the node is a leaf.
at line 1374
string
getLftName()
Get the lft key name.
at line 1382
string
getRgtName()
Get the rgt key name.
at line 1390
string
getParentIdName()
Get the parent id key name.
at line 1398
string
getDepthName()
Get the depth column name.
at line 1406
int|null
getLft()
Get the value of the model's lft key.
at line 1416
int|null
getRgt()
Get the value of the model's rgt key.
at line 1426
int|string|null
getParentId()
Get the value of the model's parent id key.
at line 1434
int|null
getDepth()
Get the node depth.
at line 1447
Model|null
getNextNode(array $columns = ['*'])
Return the node that is next to the current node without constraining to siblings.
This can be either a next sibling or a next sibling of the parent node.
at line 1458
Model|null
getPrevNode(array $columns = ['*'])
Return the node that is before the current node without constraining to siblings.
This can be either a prev sibling or parent node.
at line 1468
Collection
getAncestors(array $columns = ['*'])
Get the node's ancestors.
at line 1478
Collection
getDescendants(array $columns = ['*'])
Get the node's descendants.
at line 1488
Collection
getSiblings(array $columns = ['*'])
Get the node's siblings.
at line 1498
Collection
getNextSiblings(array $columns = ['*'])
Get siblings after the node.
at line 1508
Collection
getPrevSiblings(array $columns = ['*'])
Get siblings before the node.
at line 1518
Model|null
getNextSibling(array $columns = ['*'])
Get the next sibling.
at line 1528
Model|null
getPrevSibling(array $columns = ['*'])
Get the previous sibling.
at line 1536
bool
isDescendantOf(HasNode $other)
Get whether a node is a descendant of other node.
at line 1556
bool
isSelfOrDescendantOf(HasNode $other)
Get whether a node is itself or a descendant of other node.
at line 1580
bool
isChildOf(HasNode $other)
Get whether the node is immediate children of other node.
at line 1596
bool
isSiblingOf(HasNode $other)
Get whether the node is a sibling of another node.
at line 1619
bool
isAncestorOf(HasNode $other)
Get whether the node is an ancestor of other node, including immediate parent.
at line 1627
bool
isSelfOrAncestorOf(HasNode $other)
Get whether the node is itself or an ancestor of other node, including immediate parent.
at line 1635
bool
hasMoved()
Get whether the node has moved since last save.
at line 1643
protected bool
hardDeleting()
Get whether user is intended to delete the model from database entirely.
at line 1653
array
getBounds()
Get the node bounds.
at line 1661
HasNode
setLft(int|null $value)
Set the left bound.
at line 1671
HasNode
setRgt(int|null $value)
Set the right bound.
at line 1681
HasNode
setParentId(int|string|null $value)
Set the parent key.
at line 1692
HasNode
setDepth(int|null $value)
Set the node depth.
at line 1702
protected HasNode
dirtyBounds()
Mark the stored bounds as dirty.
at line 1713
protected void
unsetNestedSetRelations()
Forget relations derived from the node's structural position.
at line 1733
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 1760
protected HasNode
assertNotDescendant(HasNode $node)
Assert that a node is neither this node nor one of its descendants.
at line 1772
protected HasNode
assertNodeExists(HasNode $node)
Assert that a node has positive tree bounds.
at line 1784
protected void
ensureBoundsLoaded()
Ensure that this node has loaded bounds.
at line 1797
protected void
ensureParentageLoaded()
Ensure that this node has loaded parentage.
at line 1810
protected void
ensureScopeLoaded()
Ensure that this node has loaded scope attributes.
at line 1826
protected HasNode
ensureSameTree(HasNode $node)
Ensure that a node belongs to the same nested set tree.
at line 1838
protected bool
isSameScope(HasNode $node)
Determine whether a node belongs to the same concrete scope.
at line 1848
protected bool
isSameTree(HasNode $node)
Determine whether the models address the same nested set tree.
at line 1857
protected bool
isSameNode(HasNode $node)
Determine whether the models address the same persisted row.
at line 1877
HasNode
replicate(array|null $except = null)
Clone the node without structural attributes.