Download the PHP package uccello/eloquent-tree without Composer
On this page you can find all versions of the php package uccello/eloquent-tree. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uccello/eloquent-tree
More information about uccello/eloquent-tree
Files in uccello/eloquent-tree
Package eloquent-tree
Short Description Eloquent Tree transforms a model into tree model for Laravel Eloquent ORM.
License MIT
Informations about the package eloquent-tree
eloquent-tree
Eloquent Tree transforms a model into tree model for Laravel Eloquent ORM.
This project is based on the original project made by Adrian Skierniewski. It was changed to be able to use this functionnality thanks to the IsTree
trait, instead of extending the Tree
model. It is useful if you want your model extends another class.
Table of Contents
- Features
- Installation
- Migration
- Example usage
- Events
- Support
Features
- Creating root, children and sibling nodes
- Getting children
- Getting descendants
- Getting ancestor
- Moving sub-tree
- Building tree on PHP side
Installation
For Laravel >= 5.3
Begin by installing this package through Composer. Edit your project's composer.json file to require uccello/eloquent-tree.
Next, update Composer from the Terminal:
That's all now you can extend \Gzero\EloquentTree\Model\Tree in your project
Migration
Simply migration with all required columns that you could extend by adding new fields
Example usage
- Inserting and Updating new nodes
- Getting tree nodes
- Finding Leaf nodes
- Map from array
- Rendering tree
Inserting and updating new nodes
Getting tree nodes
Leaf - returning root node
Children - returning flat collection of children. You can use Eloquent query builder.
Ancestors - returning flat collection of ancestors, first is root, last is current node. You can use Eloquent query builder. Of course there are no guarantees that the structure of the tree would be complete if you do the query with additional where
Descendants - returning flat collection of descendants, first is current node, last is leafs. You can use Eloquent query builder. Of course there are no guarantees that the structure of the tree would be complete if you do the query with additional where
Building tree structure on PHP side - if some nodes will be missing, these branches will not be built
Getting leaf nodes
Map from array
Three new roots, first with descendants
Rendering tree
You can render tree built by the function buildTree
Events
All tree models have additional events:
- updatingParent
- updatedParent
- updatedDescendants
You can use them for example to update additional tables
Credits
- All Contributors
License
The MIT License (MIT). Please see License File for more information.