trait HasNode

Properties

protected array $pending

Pending operations.

protected bool $moved

Whether the node has moved since last save.

static protected bool|null $hasSoftDelete

Whether the node has soft delete.

int $parent_id
?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()

No description

bool
actionRaw()

No description

bool
actionRoot()

Make a root node.

int
getLowerBound()

Get the lower bound.

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

Append or prepend a node to the parent.

setParent(Model|null $value)

Apply parent model.

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

Insert node before or after another node.

void
refreshNode()

Refresh node's crucial attributes.

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 node siblings and the node itself.

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

Get query for 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)

No description

afterNode(HasNode $node)

Insert self after a node.

beforeNode(HasNode $node)

Insert self before node.

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

No description

bool
insertAfterNode(HasNode $node)

Insert self after a node and save.

bool
insertBeforeNode(HasNode $node)

Insert self before a node and save.

rawNode(mixed $lft, mixed $rgt, mixed $parentId)

No description

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)

Insert node at specific position.

bool
moveNode(int $position)

Move a node to the new position.

bool
insertNode(int $position)

Insert new node at specified position.

void
deleteDescendants()

Update the tree when the node is removed physically.

void
restoreDescendants(CarbonInterface|string $deletedAt)

Restore the descendants.

newModelBuilder(Builder $query)

Create a new Model query builder for the model.

mixed
newNestedSetQuery(string|null $table = null)

Get a new base query that includes deleted nodes.

mixed
newScopedQuery(string|null $table = null)

No description

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

No description

array
getScopeAttributes()

No description

static mixed
scoped(array $attributes)

No description

newCollection(array $models = [])

No description

static HasNode|null
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|null $value)

Set the value of model's parent id key.

bool
isRoot()

Get whether node is root.

bool
isLeaf()

No description

string
getLftName()

Get the lft key name.

string
getRgtName()

Get the rgt key name.

string
getParentIdName()

Get the parent id key 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|null
getParentId()

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

mixed
getNextNode(array $columns = ['*'])

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

mixed
getPrevNode(array $columns = ['*'])

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

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

No description

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

No description

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

No description

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

No description

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

No description

mixed
getNextSibling(array $columns = ['*'])

No description

mixed
getPrevSibling(array $columns = ['*'])

No description

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.

array
getArrayableRelations()

No description

bool
hasForceDeleting()

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

array
getBounds()

No description

setLft(mixed $value)

No description

setRgt(mixed $value)

No description

setParentId(mixed $value)

No description

dirtyBounds()

No description

assertNotDescendant(HasNode $node)

No description

assertNodeExists(HasNode $node)

No description

void
assertSameScope(HasNode $node)

No description

bool
isSameScope(HasNode $node)

No description

replicate(array|null $except = null)

No description

Details

at line 47
QueryBuilder newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

Parameters

Builder $query

Return Value

QueryBuilder

at line 55
static void bootHasNode()

Bootstrap node events.

Return Value

void

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

Set an action.

Parameters

string $action
mixed ...$args

Return Value

HasNode

at line 86
protected void callPendingActions()

Call pending action.

Return Value

void

at line 106
static bool usesSoftDelete()

No description

Return Value

bool

at line 119
protected bool actionRaw()

No description

Return Value

bool

at line 127
protected bool actionRoot()

Make a root node.

Return Value

bool

at line 145
protected int getLowerBound()

Get the lower bound.

Return Value

int

at line 153
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 170
protected HasNode setParent(Model|null $value)

Apply parent model.

Parameters

Model|null $value

Return Value

HasNode

at line 181
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 191
void refreshNode()

Refresh node's crucial attributes.

Return Value

void

at line 205
BelongsTo parent()

Relation to the parent.

Return Value

BelongsTo

at line 214
HasMany children()

Relation to children.

Return Value

HasMany

at line 223
DescendantsRelation descendants()

Get query for descendants of the node.

Return Value

DescendantsRelation

at line 231
QueryBuilder siblings()

Get query for siblings of the node.

Return Value

QueryBuilder

at line 241
QueryBuilder siblingsAndSelf()

Get the node siblings and the node itself.

Return Value

QueryBuilder

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

Get query for the node siblings and the node itself.

Parameters

array $columns

Return Value

Collection

at line 260
QueryBuilder nextSiblings()

Get query for siblings after the node.

Return Value

QueryBuilder

at line 269
QueryBuilder prevSiblings()

Get query for siblings before the node.

Return Value

QueryBuilder

at line 278
QueryBuilder nextNodes()

Get query for nodes after current node.

Return Value

QueryBuilder

at line 287
QueryBuilder prevNodes()

Get query for nodes before current node in reversed order.

Return Value

QueryBuilder

at line 296
AncestorsRelation ancestors()

Get query ancestors of the node.

Return Value

AncestorsRelation

at line 304
HasNode makeRoot()

Make this node a root node.

Return Value

HasNode

at line 314
bool saveAsRoot()

Save node as root.

Return Value

bool

at line 326
bool appendNode(HasNode $node)

Append and save a node.

Parameters

HasNode $node

Return Value

bool

at line 334
bool prependNode(HasNode $node)

Prepend and save a node.

Parameters

HasNode $node

Return Value

bool

at line 342
HasNode appendToNode(HasNode $parent)

Append a node to the new parent.

Parameters

HasNode $parent

Return Value

HasNode

at line 350
HasNode prependToNode(HasNode $parent)

Prepend a node to the new parent.

Parameters

HasNode $parent

Return Value

HasNode

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

No description

Parameters

HasNode $parent
bool $prepend

Return Value

HasNode

at line 369
HasNode afterNode(HasNode $node)

Insert self after a node.

Parameters

HasNode $node

Return Value

HasNode

at line 377
HasNode beforeNode(HasNode $node)

Insert self before node.

Parameters

HasNode $node

Return Value

HasNode

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

No description

Parameters

HasNode $node
bool $after

Return Value

HasNode

at line 400
bool insertAfterNode(HasNode $node)

Insert self after a node and save.

Parameters

HasNode $node

Return Value

bool

at line 408
bool insertBeforeNode(HasNode $node)

Insert self before a node and save.

Parameters

HasNode $node

Return Value

bool

at line 420
HasNode rawNode(mixed $lft, mixed $rgt, mixed $parentId)

No description

Parameters

mixed $lft
mixed $rgt
mixed $parentId

Return Value

HasNode

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

Move node up given amount of positions.

Parameters

int $amount

Return Value

bool

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

Move node down given amount of positions.

Parameters

int $amount

Return Value

bool

at line 464
protected bool insertAt(int $position)

Insert node at specific position.

Parameters

int $position

Return Value

bool

at line 476
protected bool moveNode(int $position)

Move a node to the new position.

Parameters

int $position

Return Value

bool

at line 491
protected bool insertNode(int $position)

Insert new node at specified position.

Parameters

int $position

Return Value

bool

at line 506
protected void deleteDescendants()

Update the tree when the node is removed physically.

Return Value

void

at line 532
protected void restoreDescendants(CarbonInterface|string $deletedAt)

Restore the descendants.

Parameters

CarbonInterface|string $deletedAt

Return Value

void

at line 544
QueryBuilder newModelBuilder(Builder $query)

Create a new Model query builder for the model.

Parameters

Builder $query

Return Value

QueryBuilder

at line 552
mixed newNestedSetQuery(string|null $table = null)

Get a new base query that includes deleted nodes.

Parameters

string|null $table

Return Value

mixed

at line 561
mixed newScopedQuery(string|null $table = null)

No description

Parameters

string|null $table

Return Value

mixed

at line 566
mixed applyNestedSetScope(mixed $query, string|null $table = null)

No description

Parameters

mixed $query
string|null $table

Return Value

mixed

at line 587
protected array getScopeAttributes()

No description

Return Value

array

at line 592
static mixed scoped(array $attributes)

No description

Parameters

array $attributes

Return Value

mixed

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

No description

Parameters

array $models

Return Value

Collection

at line 612
static HasNode|null 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|null

at line 640
int getNodeHeight()

Get node height (rgt - lft + 1).

Return Value

int

at line 652
int getDescendantCount()

Get number of descendant nodes.

Return Value

int

at line 663
void setParentIdAttribute(int|null $value)

Set the value of model's parent id key.

Behind the scenes node is appended to found parent node.

Parameters

int|null $value

Return Value

void

Exceptions

Exception

at line 679
bool isRoot()

Get whether node is root.

Return Value

bool

at line 684
bool isLeaf()

No description

Return Value

bool

at line 692
string getLftName()

Get the lft key name.

Return Value

string

at line 700
string getRgtName()

Get the rgt key name.

Return Value

string

at line 708
string getParentIdName()

Get the parent id key name.

Return Value

string

at line 716
int|null getLft()

Get the value of the model's lft key.

Return Value

int|null

at line 726
int|null getRgt()

Get the value of the model's rgt key.

Return Value

int|null

at line 736
int|null getParentId()

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

Return Value

int|null

at line 747
mixed 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

mixed

at line 758
mixed 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

mixed

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

No description

Parameters

array $columns

Return Value

Collection

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

No description

Parameters

array $columns

Return Value

Collection

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

No description

Parameters

array $columns

Return Value

Collection

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

No description

Parameters

array $columns

Return Value

Collection

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

No description

Parameters

array $columns

Return Value

Collection

at line 806
mixed getNextSibling(array $columns = ['*'])

No description

Parameters

array $columns

Return Value

mixed

at line 814
mixed getPrevSibling(array $columns = ['*'])

No description

Parameters

array $columns

Return Value

mixed

at line 822
bool isDescendantOf(HasNode $other)

Get whether a node is a descendant of other node.

Parameters

HasNode $other

Return Value

bool

at line 832
bool isSelfOrDescendantOf(HasNode $other)

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

Parameters

HasNode $other

Return Value

bool

at line 841
bool isChildOf(HasNode $other)

Get whether the node is immediate children of other node.

Parameters

HasNode $other

Return Value

bool

at line 849
bool isSiblingOf(HasNode $other)

Get whether the node is a sibling of another node.

Parameters

HasNode $other

Return Value

bool

at line 857
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 865
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 873
bool hasMoved()

Get whether the node has moved since last save.

Return Value

bool

at line 878
protected array getArrayableRelations()

No description

Return Value

array

at line 890
protected bool hasForceDeleting()

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

Return Value

bool

at line 898
array getBounds()

No description

Return Value

array

at line 903
HasNode setLft(mixed $value)

No description

Parameters

mixed $value

Return Value

HasNode

at line 910
HasNode setRgt(mixed $value)

No description

Parameters

mixed $value

Return Value

HasNode

at line 917
HasNode setParentId(mixed $value)

No description

Parameters

mixed $value

Return Value

HasNode

at line 924
protected HasNode dirtyBounds()

No description

Return Value

HasNode

at line 932
protected HasNode assertNotDescendant(HasNode $node)

No description

Parameters

HasNode $node

Return Value

HasNode

at line 941
protected HasNode assertNodeExists(HasNode $node)

No description

Parameters

HasNode $node

Return Value

HasNode

at line 950
protected void assertSameScope(HasNode $node)

No description

Parameters

HasNode $node

Return Value

void

at line 963
protected bool isSameScope(HasNode $node)

No description

Parameters

HasNode $node

Return Value

bool

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

No description

Parameters

array|null $except

Return Value

HasNode