PHPackages                             falco442/lumen-treeview - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. falco442/lumen-treeview

ActiveLibrary[Framework](/categories/framework)

falco442/lumen-treeview
=======================

Something to help manage tree data structures

v1.0.0(3y ago)05MITPHPPHP ^8.0

Since Aug 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/falco442/lumen-treeview)[ Packagist](https://packagist.org/packages/falco442/lumen-treeview)[ Docs](https://falco442.github.io/lumen-treeview/)[ RSS](/packages/falco442-lumen-treeview/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

falco442/lumen-treeview
=======================

[](#falco442lumen-treeview)

[![Total Downloads](https://camo.githubusercontent.com/25bebee3fa8c4b34b9d5c1ba47e1ee044bffaeb884b29114c9c80c9efb32fe0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66616c636f3434322f6c756d656e2d7472656576696577)](https://packagist.org/packages/falco442/lumen-treeview)[![Latest Stable Version](https://camo.githubusercontent.com/fb006069bbb43f5da23a04dd93e32fb4585b6097a0334498f9edcd957837de17/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66616c636f3434322f6c756d656e2d7472656576696577)](https://packagist.org/packages/falco442/lumen-treeview)[![License](https://camo.githubusercontent.com/4e3df7dee56966fde96fae4fdeecc5bd600b648fa2c26b5d768ea5bc637a86b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66616c636f3434322f6c756d656e2d7472656576696577)](https://packagist.org/packages/falco442/lumen-treeview)

This package is intended for generating a tree structure from flat data (array); it makes use of the class `Illuminate\Support\Collection`, so is intended for Lumen/Laravel projects.

Requirements
============

[](#requirements)

- PHP &gt;= 8.0
- OpenSSL PHP Extension
- PDO PHP Extension
- Mbstring PHP Extension
- laravel/lumen-framework &gt;= 9.0

Installation
============

[](#installation)

from command line, in the root folder of your Laravel/Lumen project, run the command

```
composer require falco442/lumen-treeview

```

Parameters
==========

[](#parameters)

### Static method `getTree()`

[](#static-method-gettree)

nametypedefault valuedescription`$array`arraynone. required.this is the array to pass.`$parentIdField`string`'parent_id'`the name for the parent field with which is constructed the relation`$idField`string`'id'`the name for the main field of the array, usually the primary key of the table from which data are taken`$childrenField`string`'children'`the name for the field which to put the children in, in the returned tree### Static method `getNode()`

[](#static-method-getnode)

nametypedefault valuedescription`$array`arraynone. required.this is the array to pass. **Is taken by reference**`$id`string || numbernone. required.The id of the node to take for which construct the tree`$parentIdField`string`'parent_id'`the name for the parent field with which is constructed the relation`$idField`string`'id'`the name for the main field of the array, usually the primary key of the table from which data are taken`$childrenField`string`'children'`the name for the field which to put the children in, in the returned tree`$node`arraynullThe node instance to pass to the method. **optional**, and not to be used to construct the tree. **Internal use only.**Usage
-----

[](#usage)

### Get all trees (root nodes as array of nodes)

[](#get-all-trees-root-nodes-as-array-of-nodes)

You can call the function `getTree()` to an array of arrays (for example a collection got from Eloquent) like this:

```
