Methods |
public
static
|
bootBelongsToTree()
|
#
|
public
|
getParentForeignKeyName(): string
Returns the name of the "parent_id" column.
Returns the name of the "parent_id" column.
|
#
|
public
|
getClosureTable(): string
Returns the name of the closure table.
Returns the name of the closure table.
|
#
|
public
|
deleteNode(): bool|null
Deletes the model after having attached its children to its parent.
Deletes the model after having attached its children to its parent.
Throws
|
#
|
public
|
deleteTree(): bool|null
Deletes the model and its descendants from the database.
Deletes the model and its descendants from the database.
Throws
|
#
|
public
|
parent(): BelongsTo
|
#
|
public
|
children(): HasMany
|
#
|
public
|
ancestors(): BelongsToMany
|
#
|
public
|
descendants(): BelongsToMany
|
#
|
public
|
setRelation(string $relation, mixed $value): $this
|
#
|
protected
|
setChildrenFromDescendants(Collection $descendants): $this
Automatically sets the "children" (for the current object and each of
its loaded descendants) when the "descendants"…
Automatically sets the "children" (for the current object and each of
its loaded descendants) when the "descendants" relationship is loaded.
|
#
|
protected
|
setParentsFromAncestors(Collection $ancestors): $this
Automatically sets the "parent" (for the current object and each of
its loaded ancestors) when the "ancestors"…
Automatically sets the "parent" (for the current object and each of
its loaded ancestors) when the "ancestors" relationship is loaded.
|
#
|
public
|
isRoot(): bool
|
#
|
public
|
isLeaf(): bool
|
#
|
public
|
hasChildren(): bool
|
#
|
public
|
isChildOf($item): bool
|
#
|
public
|
isParentOf(static $item): bool
|
#
|
public
|
isDescendantOf(static $item): bool
|
#
|
public
|
isAncestorOf(static $item): bool
|
#
|
public
|
isSiblingOf(static $item): bool
|
#
|
public
|
findCommonAncestorWith(static $item): static|null
Returns the closest common ancestor with the provided $item.
May return null if the tree has multiple roots and the 2…
Returns the closest common ancestor with the provided $item.
May return null if the tree has multiple roots and the 2 items have no
common ancestor.
|
#
|
public
|
getDistanceTo(static $item): int
Returns the distance between $this and another $item.
May throw an exception if the tree has multiple roots and the 2…
Returns the distance between $this and another $item.
May throw an exception if the tree has multiple roots and the 2 items
have no common ancestor.
Throws
|
#
|
public
|
getDepth(): int
Return the depth of $this in the tree (0 is $this is a root).
Return the depth of $this in the tree (0 is $this is a root).
|
#
|
public
|
getSubtreeDepth(): int
Returns the depth of the subtree of which $this is a root.
Returns the depth of the subtree of which $this is a root.
|
#
|
protected
|
scopeWithClosure($query, $relation, $depth = null, $constraints = null)
|
#
|
public
|
scopeWithAncestors($query, $depth = null, $constraints = null)
|
#
|
public
|
scopeWithDescendants($query, $depth = null, $constraints = null)
|
#
|
public
|
scopeWithDepth($query, $as = 'depth')
|
#
|
public
|
scopeWhereIsRoot($query, $bool = true)
|
#
|
public
|
scopeWhereIsLeaf($query, $bool = true)
|
#
|
public
|
scopeWhereHasChildren($query, $bool = true)
|
#
|
public
|
scopeWhereIsDescendantOf($query, $ancestor, $maxDepth = null, $includingSelf = false)
|
#
|
public
|
scopeWhereIsAncestorOf($query, $descendant, $maxDepth = null, $includingSelf = false)
|
#
|
public
static
|
getTree(int $depth = null): Collection
Shortcut method that returns a collection of the tree roots, with their
eager-loaded descendants.
Shortcut method that returns a collection of the tree roots, with their
eager-loaded descendants.
|
#
|
public
static
|
getTreeDepth(): int
Return the depth of the tree (0 if the tree is flat).
Return the depth of the tree (0 if the tree is flat).
|
#
|
protected
|
checkIfParentIdIsValid(): void
Check if the parent_id points to a descendant of the current object
(and trigger an exception if it's the case).
Check if the parent_id points to a descendant of the current object
(and trigger an exception if it's the case).
Throws
|
#
|
public
|
refreshClosures(bool $deleteOldClosures = true)
Re-calculate the closures when the parent_id has changed on a single item.
Re-calculate the closures when the parent_id has changed on a single item.
Parameters
$deleteOldClosures |
Can be set to false if it's a new item
|
|
#
|
protected
|
deleteClosuresForLeaf()
Deletes the closures for the item. Assumes that the item has no children.
Deletes the closures for the item. Assumes that the item has no children.
|
#
|