Download the PHP package dcblogdev/laravel-nestable without Composer
On this page you can find all versions of the php package dcblogdev/laravel-nestable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-nestable
Laravel Nestable
Forked from https://github.com/atayahmet/laravel-nestable due to being archived and needing the package to support Laravel 6. Thanks to Ahmet for this package.
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
Then
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:
Helper
All versions of laravel-nestable with dependencies
illuminate/support Version 5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*|10.*|11.*
illuminate/database Version 5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*|10.*|11.*