Download the PHP package gregoryduckworth/nestablecollection without Composer
On this page you can find all versions of the php package gregoryduckworth/nestablecollection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gregoryduckworth/nestablecollection
More information about gregoryduckworth/nestablecollection
Files in gregoryduckworth/nestablecollection
Package nestablecollection
Short Description A Laravel Package that extends Collection to handle unlimited nested items following adjacency list model.
License MIT
Informations about the package nestablecollection
NestableCollection
A Laravel/Lumen Package that extends Collection to handle unlimited nested items following adjacency list model.
Installation
Run
Usage
The model must have a parent_id attributes :
and must use the following trait:
Now each time you get a collection of that model, it will be an instance of TypiCMS\NestableCollection in place of Illuminate\Database\Eloquent\Collection.
If you want a tree of models, simply call the nest method on a collection ordered by parent_id asc and pass the column on which you want the nesting to occurr :
Of course you will probably want a position column as well. So you will have to order first by parent_id asc and then by position asc.
Indented and flattened list
method generate the tree as a flattened list with id as keys and title as values, perfect for select/option, for example :
To use it, first call the nest()
method, followed by the listsFlattened()
method:
By default it will look for a title
column. You can send a custom column name as first parameter:
Four spaces are used to indent by default, to use your own use the setIndent()
method, followed by the listsFlattened()
method:
Results:
Nesting a subtree
This package remove items that have missing ancestor, this doesn’t allow you to nest a branch of a tree. To avoid this, you can use the method: