Tree
Manage models with parent - child relations.
Change parrent id column name in model: protected $parentColumn = 'column name';
Table of Contents
Methods
- deleteChilds() : bool
- Delete recursive
- getModelPath() : array<string|int, mixed>
- Get model tree
- getParentColumn() : string
- Get parent id attribute name default: parent_id
- getTreePath() : array<string|int, mixed>
- Gte model tree for current model
- hasChild() : bool
- Return true if model item have child items
- scopeChildListQuery() : Builder
- Childs list query
- scopeRootQuery() : object
- Query for root items
Methods
deleteChilds()
Delete recursive
public
deleteChilds(string|int $id[, Closure|null $callback = null ]) : bool
Parameters
- $id : string|int
- $callback : Closure|null = null
Return values
boolgetModelPath()
Get model tree
public
getModelPath(Moldel $model) : array<string|int, mixed>
Parameters
- $model : Moldel
Return values
array<string|int, mixed>getParentColumn()
Get parent id attribute name default: parent_id
public
getParentColumn() : string
Return values
stringgetTreePath()
Gte model tree for current model
public
getTreePath() : array<string|int, mixed>
Return values
array<string|int, mixed>hasChild()
Return true if model item have child items
public
hasChild([int|string|null $id = null ]) : bool
Parameters
- $id : int|string|null = null
Return values
boolscopeChildListQuery()
Childs list query
public
scopeChildListQuery(Builder $query, int $id) : Builder
Parameters
- $query : Builder
- $id : int
Return values
BuilderscopeRootQuery()
Query for root items
public
scopeRootQuery(Builder $query) : object
Parameters
- $query : Builder