Download the PHP package ultrono/laravel-nestable without Composer
On this page you can find all versions of the php package ultrono/laravel-nestable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-nestable
Laravel 5.8 / 6x / 7x / 8x / 9x / 10x / 11x Nestable
Note: Unfortunately the original repository has been marked as read only by the author. This is a fork created with very limited time to add for Laravel 6, 7 and 8 support. I've not yet had change to run the original tests but all methods/functionality mentioned in the readme work on vanilla installs of Laravel 5.8 and above. Use this repository at your own risk as I'm unlikely to have the time to maintain it further. |
---|
Laravel Nestable to work with recursive logic. Category level there is no limit but this may vary depending on your server performance. Allow the 100000 recursion process execution since PHP 5.2. More info
Install
If using a Laravel version less than 5.5, add to app.php the Service Provider file.
Then add app.php Facade file again.
Finally run the artisan command:
That's it!
Basic Usage with Eloquent
Suppose that the data came from a database as follows.
Category table:
id | parent_id | name | slug |
---|---|---|---|
1 | 0 | T-shirts | t-shirts |
2 | 1 | Red T-shirts | red-t-shirts |
3 | 1 | Black T-shirts | black-t-shirts |
4 | 0 | Sweaters | sweaters |
5 | 4 | Red Sweaters | red-sweaters |
6 | 4 | Blue Sweaters | blue-sweaters |
Example 1:
Note: $parent variable refers to the parent category (Default parent_id)
Query result:
For html tree output:
Output:
For dropdown output:
Output:
Selected for multiple list box:
Output methods
name | Parameter | output |
---|---|---|
renderAsArray() | none | array |
renderAsJson() | none | json |
renderAsHtml() | none | html |
renderAsDropdown() | none | dropdown |
renderAsMultiple() | none | Listbox |
Usable methods with output methods
renderAsArray()
name | paremeter | description |
---|---|---|
parent() | int | Get childs of the defined parent |
renderAsJson()
name | paremeter | description |
---|---|---|
parent() | int | Get childs of the defined parent |
renderAsHtml()
name | paremeter | description |
---|---|---|
parent() | int | Get childs of the defined parent |
active() | callback/array/int | Selected item(s) for html output |
ulAttr() | array/string | Add attribute to parent ul element |
firstUlAttr() | array/string | Add attribute to parent ul element |
route() | callback/array | Generate url by route name |
customUrl() | string | Generate custom url |
renderAsDropdown()/renderAsMultiple()
name | paremeter | description |
---|---|---|
parent() | int | Get childs of the defined parent |
selected() | callback/array/int | Selected item(s) for dropdown |
attr() | array | Dropdown/listbox attributes |
parent()
Get childs of the defined parent.
Note: This methods usable all with output methods
active()
Selected item(s) for html output.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
firstUlAttr()
Add attribute to first ul element
Example 1:
Example 2:
ulAttr()
Add attribute to parent ul element
Example 1:
Example 2:
Example 3:
route()
Generate url by route name
Example 1:
Note: product refer to route name and slug refer to paremeter name.
Example 2:
customUrl()
Generate custom url with slug
Example 1:
Example 1:
Note: slug keyword belongs to html > href in config file.
selected()
Selected item(s) for dropdown.
Example 1:
Example 2:
Example 3:
Example 4:
attr()
Dropdown/listbox attributes.
Configuration
The above examples were performed with default settings. Config variables in config/nestable.php file.
name | type | description |
---|---|---|
parent | string | Parent category column name |
primary_key | string | Table primary key |
generate_url | boolean | Generate the url for html output |
childNode | string | Child node name |
body | array | Array output (default) |
html | array | Html output columns |
dropdown | array | Dropdown/Listbox output |
body
The body variable should be an array and absolutely customizable.
Example:
html
Configuration for html output.
name | description |
---|---|
label | Label column name |
href | Url column name |
Example:
dropdown
Configuration for dropdown/listbox output.
name | description |
---|---|
prefix | Label prefix |
label | Label column name |
value | Value column name |
Example:
Using Independent Models
Include the Nestable facade.
For array output:
Validators
It controls the structure of the data. They also made the rendering process with a second parameter control after they.
name | Parameters |
---|---|
isValidForArray | boolean |
isValidForJson | boolean |
isValidForHtml | boolean |
isValidForDropdown | boolean |
isValidForMultiple | boolean |
Example 1:
Example 2:
Macros
Call the above macro: