{"id":22447094,"url":"https://github.com/imajkumar/laravel-binary-tree","last_synced_at":"2025-06-28T07:33:06.364Z","repository":{"id":56990197,"uuid":"182957374","full_name":"imajkumar/laravel-binary-tree","owner":"imajkumar","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-15T05:59:18.000Z","size":36,"stargazers_count":13,"open_issues_count":0,"forks_count":11,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-23T16:20:18.025Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imajkumar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-23T07:19:15.000Z","updated_at":"2024-04-01T05:29:28.000Z","dependencies_parsed_at":"2022-08-21T13:50:16.859Z","dependency_job_id":null,"html_url":"https://github.com/imajkumar/laravel-binary-tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajkumar%2Flaravel-binary-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajkumar%2Flaravel-binary-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajkumar%2Flaravel-binary-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajkumar%2Flaravel-binary-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imajkumar","download_url":"https://codeload.github.com/imajkumar/laravel-binary-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228407862,"owners_count":17915083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T04:14:22.755Z","updated_at":"2024-12-06T04:14:23.817Z","avatar_url":"https://github.com/imajkumar.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel-binary-tree\nfor laravel 5.8\n\nAn easy way to visualize how a nested set works is to think of a parent entity surrounding all\nof its children, and its parent surrounding it, etc. So this tree:\n\n    root\n      |_ Child 1\n        |_ Child 1.1\n        |_ Child 1.2\n      |_ Child 2\n        |_ Child 2.1\n        |_ Child 2.2\n\n\nCould be visualized like this:\n\n     ___________________________________________________________________\n    |  Root                                                             |\n    |    ____________________________    ____________________________   |\n    |   |  Child 1                  |   |  Child 2                  |   |\n    |   |   __________   _________  |   |   __________   _________  |   |\n    |   |  |  C 1.1  |  |  C 1.2 |  |   |  |  C 2.1  |  |  C 2.2 |  |   |\n    1   2  3_________4  5________6  7   8  9_________10 11_______12 13  14\n    |   |___________________________|   |___________________________|   |\n    |___________________________________________________________________|\n\nThe numbers represent the left and right boundaries.  The table then might\nlook like this:\n\n    id | parent_id | lft  | rgt  | depth | data\n     1 |           |    1 |   14 |     0 | root\n     2 |         1 |    2 |    7 |     1 | Child 1\n     3 |         2 |    3 |    4 |     2 | Child 1.1\n     4 |         2 |    5 |    6 |     2 | Child 1.2\n     5 |         1 |    8 |   13 |     1 | Child 2\n     6 |         5 |    9 |   10 |     2 | Child 2.1\n     7 |         5 |   11 |   12 |     2 | Child 2.2\n\nTo get all children of a _parent_ node, you\n\n```sql\nSELECT * WHERE lft IS BETWEEN parent.lft AND parent.rgt\n```\n\nTo get the number of children, it's\n\n```sql\n(right - left - 1)/2\n```\n\nTo get a node and all its ancestors going back to the root, you\n\n```sql\nSELECT * WHERE node.lft IS BETWEEN lft AND rgt\n```\n\nAs you can see, queries that would be recursive and prohibitively slow on\nordinary trees are suddenly quite fast. Nifty, isn't it?\n\n\n\n\u003ca name=\"creating-root-node\"\u003e\u003c/a\u003e\n### Creating a root node\n\nBy default, all nodes are created as roots:\n\n```php\n$root = Category::create(['name' =\u003e 'Root category']);\n```\n\nAlternatively, you may find yourself in the need of *converting* an existing node\ninto a *root node*:\n\n```php\n$node-\u003emakeRoot();\n```\n\nYou may also nullify it's `parent_id` column to accomplish the same behaviour:\n\n```php\n// This works the same as makeRoot()\n$node-\u003eparent_id = null;\n$node-\u003esave();\n```\n\n\u003ca name=\"inserting-nodes\"\u003e\u003c/a\u003e\n### Inserting nodes\n\n```php\n// Directly with a relation\n$child1 = $root-\u003echildren()-\u003ecreate(['name' =\u003e 'Child 1']);\n\n// with the `makeChildOf` method\n$child2 = Category::create(['name' =\u003e 'Child 2']);\n$child2-\u003emakeChildOf($root);\n```\n\n\u003ca name=\"deleting-nodes\"\u003e\u003c/a\u003e\n### Deleting nodes\n\n```php\n$child1-\u003edelete();\n```\n\nDescendants of deleted nodes will also be deleted and all the `lft` and `rgt`\nbound will be recalculated. Pleases note that, for now, `deleting` and `deleted`\nmodel events for the descendants will not be fired.\n\n\u003ca name=\"node-level\"\u003e\u003c/a\u003e\n### Getting the nesting level of a node\n\nThe `getLevel()` method will return current nesting level, or depth, of a node.\n\n```php\n$node-\u003egetLevel() // 0 when root\n```\n\n\u003ca name=\"moving-nodes\"\u003e\u003c/a\u003e\n### Moving nodes around\n\nBaum provides several methods for moving nodes around:\n\n* `moveLeft()`: Find the left sibling and move to the left of it.\n* `moveRight()`: Find the right sibling and move to the right of it.\n* `moveToLeftOf($otherNode)`: Move to the node to the left of ...\n* `moveToRightOf($otherNode)`: Move to the node to the right of ...\n* `makeNextSiblingOf($otherNode)`: Alias for `moveToRightOf`.\n* `makeSiblingOf($otherNode)`: Alias for `makeNextSiblingOf`.\n* `makePreviousSiblingOf($otherNode)`: Alias for `moveToLeftOf`.\n* `makeChildOf($otherNode)`: Make the node a child of ...\n* `makeFirstChildOf($otherNode)`: Make the node the first child of ...\n* `makeLastChildOf($otherNode)`: Alias for `makeChildOf`.\n* `makeRoot()`: Make current node a root node.\n\nFor example:\n\n```php\n$root = Creatures::create(['name' =\u003e 'The Root of All Evil']);\n\n$dragons = Creatures::create(['name' =\u003e 'Here Be Dragons']);\n$dragons-\u003emakeChildOf($root);\n\n$monsters = new Creatures(['name' =\u003e 'Horrible Monsters']);\n$monsters-\u003esave();\n\n$monsters-\u003emakeSiblingOf($dragons);\n\n$demons = Creatures::where('name', '=', 'demons')-\u003efirst();\n$demons-\u003emoveToLeftOf($dragons);\n```\n\n\u003ca name=\"node-questions\"\u003e\u003c/a\u003e\n### Asking questions to your nodes\n\nYou can ask some questions to your Baum nodes:\n\n* `isRoot()`: Returns true if this is a root node.\n* `isLeaf()`: Returns true if this is a leaf node (end of a branch).\n* `isChild()`: Returns true if this is a child node.\n* `isDescendantOf($other)`: Returns true if node is a descendant of the other.\n* `isSelfOrDescendantOf($other)`: Returns true if node is self or a descendant.\n* `isAncestorOf($other)`: Returns true if node is an ancestor of the other.\n* `isSelfOrAncestorOf($other)`: Returns true if node is self or an ancestor.\n* `equals($node)`: current node instance equals the other.\n* `insideSubtree($node)`: Checks whether the given node is inside the subtree\ndefined by the left and right indices.\n* `inSameScope($node)`: Returns true if the given node is in the same scope\nas the current one. That is, if *every* column in the `scoped` property has\nthe same value in both nodes.\n\nUsing the nodes from the previous example:\n\n```php\n$demons-\u003eisRoot(); // =\u003e false\n\n$demons-\u003eisDescendantOf($root) // =\u003e true\n```\n\n\u003ca name=\"node-relations\"\u003e\u003c/a\u003e\n### Relations\n\nprovides two self-referential Eloquent relations for your nodes: `parent`\nand `children`.\n\n```php\n$parent = $node-\u003eparent()-\u003eget();\n\n$children = $node-\u003echildren()-\u003eget();\n```\n\n\u003ca name=\"node-basic-scopes\"\u003e\u003c/a\u003e\n### Root and Leaf scopes\n\n provides some very basic query scopes for accessing the root and leaf nodes:\n\n```php\n// Query scope which targets all root nodes\nCategory::roots()\n\n// All leaf nodes (nodes at the end of a branch)\nCategory:allLeaves()\n```\n\nYou may also be interested in only the first root:\n\n```php\n$firstRootNode = Category::root();\n```\n\n\u003ca name=\"node-chains\"\u003e\u003c/a\u003e\n### Accessing the ancestry/descendancy chain\n\nThere are several methods which  offers to access the ancestry/descendancy\nchain of a node in the Nested Set tree. The main thing to keep in mind is that\nthey are provided in two ways:\n\nFirst as **query scopes**, returning an `Illuminate\\Database\\Eloquent\\Builder`\ninstance to continue to query further. To get *actual* results from these,\nremember to call `get()` or `first()`.\n\n* `ancestorsAndSelf()`: Targets all the ancestor chain nodes including the current one.\n* `ancestors()`: Query the ancestor chain nodes excluding the current one.\n* `siblingsAndSelf()`: Instance scope which targets all children of the parent, including self.\n* `siblings()`: Instance scope targeting all children of the parent, except self.\n* `leaves()`: Instance scope targeting all of its nested children which do not have children.\n* `descendantsAndSelf()`: Scope targeting itself and all of its nested children.\n* `descendants()`: Set of all children \u0026 nested children.\n* `immediateDescendants()`: Set of all children nodes (non-recursive).\n\n\n\n* `getRoot()`: Returns the root node starting at the current node.\n* `getAncestorsAndSelf()`: Retrieve all of the ancestor chain including the current node.\n* `getAncestorsAndSelfWithoutRoot()`: All ancestors (including the current node) except the root node.\n* `getAncestors()`: Get all of the ancestor chain from the database excluding the current node.\n* `getAncestorsWithoutRoot()`: All ancestors except the current node and the root node.\n* `getSiblingsAndSelf()`: Get all children of the parent, including self.\n* `getSiblings()`: Return all children of the parent, except self.\n* `getLeaves()`: Return all of its nested children which do not have children.\n* `getDescendantsAndSelf()`: Retrieve all nested children and self.\n* `getDescendants()`: Retrieve all of its children \u0026 nested children.\n* `getImmediateDescendants()`: Retrieve all of its children nodes (non-recursive).\n\nHere's a simple example for iterating a node's descendants (provided a name\nattribute is available):\n\n```php\n$node = Category::where('name', '=', 'Books')-\u003efirst();\n\nforeach($node-\u003egetDescendantsAndSelf() as $descendant) {\n  echo \"{$descendant-\u003ename}\";\n}\n```\n\n\u003ca name=\"limiting-depth\"\u003e\u003c/a\u003e\n### Limiting the levels of children returned\n\nIn some situations where the hierarchy depth is huge it might be desirable to limit the number of levels of children returned (depth). You can do this in  by using the `limitDepth` query scope.\n\nThe following snippet will get the current node's descendants up to a maximum\nof 5 depth levels below it:\n\n```php\n$node-\u003edescendants()-\u003elimitDepth(5)-\u003eget();\n```\n\nSimilarly, you can limit the descendancy levels with both the `getDescendants` and `getDescendantsAndSelf` methods by supplying the desired depth limit as the first argument:\n\n```php\n// This will work without depth limiting\n// 1. As usual\n$node-\u003egetDescendants();\n// 2. Selecting only some attributes\n$other-\u003egetDescendants(array('id', 'parent_id', 'name'));\n...\n// With depth limiting\n// 1. A maximum of 5 levels of children will be returned\n$node-\u003egetDescendants(5);\n// 2. A max. of 5 levels of children will be returned selecting only some attrs\n$other-\u003egetDescendants(5, array('id', 'parent_id', 'name'));\n```\n\n\u003ca name=\"custom-sorting-column\"\u003e\u003c/a\u003e\n### Custom sorting column\n\nBy default in  all results are returned sorted by the `lft` index column\nvalue for consistency.\n\nIf you wish to change this default behaviour you need to specify in your model\nthe name of the column you wish to use to sort your results like this:\n\n```php\nprotected $orderColumn = 'name';\n```\n\n\u003ca name=\"hierarchy-tree\"\u003e\u003c/a\u003e\n### Dumping the hierarchy tree\n\nextends the default `Eloquent\\Collection` class and provides the\n`toHierarchy` method to it which returns a nested collection representing the\nqueried tree.\n\nRetrieving a complete tree hierarchy into a regular `Collection` object with\nits children *properly nested* is as simple as:\n\n```php\n$tree = Category::where('name', '=', 'Books')-\u003efirst()-\u003egetDescendantsAndSelf()-\u003etoHierarchy();\n```\n\n\u003ca name=\"node-model-events\"\u003e\u003c/a\u003e\n### Model events: `moving` and `moved`\n\n models fire the following events: `moving` and `moved` every time a node\nis *moved* around the Nested Set tree. This allows you to hook into those points\nin the node movement process. As with normal Eloquent model events, if `false`\nis returned from the `moving` event, the movement operation will be cancelled.\n\nThe recommended way to hook into those events is by using the model's boot\nmethod:\n\n```php\nclass Category extends Ayra\\Node {\n\n  public static function boot() {\n    parent::boot();\n\n    static::moving(function($node) {\n      // Before moving the node this function will be called.\n    });\n\n    static::moved(function($node) {\n      // After the move operation is processed this function will be\n      // called.\n    });\n  }\n\n}\n```\n\n\u003ca name=\"scope-support\"\u003e\u003c/a\u003e\n### Scope support\n\n provides a simple method to provide Nested Set \"scoping\" which restricts\nwhat we consider part of a nested set tree. This should allow for multiple nested\nset trees in the same database table.\n\nTo make use of the scoping funcionality you may override the `scoped` model\nattribute in your subclass. This attribute should contain an array of the column\nnames (database fields) which shall be used to restrict Nested Set queries:\n\n```php\nclass Category extends Ayra\\Node {\n  ...\n  protected $scoped = array('company_id');\n  ...\n}\n```\n\nIn the previous example, `company_id` effectively restricts (or \"scopes\") a\nNested Set tree. So, for each value of that field we may be able to construct\na full different tree.\n\n```php\n$root1 = Category::create(['name' =\u003e 'R1', 'company_id' =\u003e 1]);\n$root2 = Category::create(['name' =\u003e 'R2', 'company_id' =\u003e 2]);\n\n$child1 = Category::create(['name' =\u003e 'C1', 'company_id' =\u003e 1]);\n$child2 = Category::create(['name' =\u003e 'C2', 'company_id' =\u003e 2]);\n\n$child1-\u003emakeChildOf($root1);\n$child2-\u003emakeChildOf($root2);\n\n$root1-\u003echildren()-\u003eget(); // \u003c- returns $child1\n$root2-\u003echildren()-\u003eget(); // \u003c- returns $child2\n```\n\nAll methods which ask or traverse the Nested Set tree will use the `scoped`\nattribute (if provided).\n\n**Please note** that, for now, moving nodes between scopes is not supported.\n\n\u003ca name=\"validation\"\u003e\u003c/a\u003e\n### Validation\n\nThe `::isValidNestedSet()` static method allows you to check if your underlying tree structure is correct. It mainly checks for these 3 things:\n\n* Check that the bound indexes `lft`, `rgt` are not null, `rgt` values greater\nthan `lft` and within the bounds of the parent node (if set).\n* That there are no duplicates for the `lft` and `rgt` column values.\n* As the first check does not actually check root nodes, see if each root has\nthe `lft` and `rgt` indexes within the bounds of its children.\n\nAll of the checks are *scope aware* and will check each scope separately if needed.\n\nExample usage, given a `Category` node class:\n\n```php\nCategory::isValidNestedSet()\n=\u003e true\n```\n\n\u003ca name=\"rebuilding\"\u003e\u003c/a\u003e\n### Tree rebuilding\n\n supports for complete tree-structure rebuilding (or reindexing) via the\n`::rebuild()` static method.\n\nThis method will re-index all your `lft`, `rgt` and `depth` column values,\ninspecting your tree only from the parent \u003c-\u003e children relation\nstandpoint. Which means that you only need a correctly filled `parent_id` column\nand  will try its best to recompute the rest.\n\nThis can prove quite useful when something has gone horribly wrong with the index\nvalues or it may come quite handy when *converting* from another implementation\n(which would probably have a `parent_id` column).\n\nThis operation is also *scope aware* and will rebuild all of the scopes\nseparately if they are defined.\n\nSimple example usage, given a `Category` node class:\n\n```php\nCategory::rebuild()\n```\n\nValid trees (per the `isValidNestedSet` method) will not get rebuilt. To force the index rebuilding process simply call the rebuild method with `true` as the first parameter:\n\n```php\nCategory::rebuild(true);\n```\n\n\u003ca name=\"soft-deletes\"\u003e\u003c/a\u003e\n### Soft deletes\n\n comes with **limited support** for soft-delete operations. What I mean\nby *limited* is that the testing is still limited and the *soft delete*\nfunctionality is changing in the upcoming 4.2 version of the framework, so use\nthis feature wisely.\n\nFor now, you may consider a **safe** `restore()` operation to be one of:\n\n* Restoring a leaf node\n* Restoring a whole sub-tree in which the parent is not soft-deleted\n\n\u003ca name=\"seeding\"\u003e\u003c/a\u003e\n### Seeding/Mass-assignment\n\nBecause Nested Set structures usually involve a number of method calls to build a hierarchy structure (which result in several database queries),  provides two convenient methods which will map the supplied array of node attributes and create a hierarchy tree from them:\n\n* `buildTree($nodeList)`: (static method) Maps the supplied array of node attributes into the database.\n* `makeTree($nodeList)`: (instance method) Maps the supplied array of node attributes into the database using the current node instance as the parent for the provided subtree.\n\nBoth methods will *create* new nodes when the primary key is not supplied, *update* or *create* if it is, and *delete* all nodes which are not present in the *affecting scope*. Understand that the *affecting scope* for the `buildTree` static method is the whole nested set tree and for the `makeTree` instance method are all of the current node's descendants.\n\nFor example, imagine we wanted to map the following category hierarchy into our database:\n\n- TV \u0026 Home Theater\n- Tablets \u0026 E-Readers\n- Computers\n  + Laptops\n    * PC Laptops\n    * Macbooks (Air/Pro)\n  + Desktops\n  + Monitors\n- Cell Phones\n\nThis could be easily accomplished with the following code:\n\n```php\n$categories = [\n  ['id' =\u003e 1, 'name' =\u003e 'TV \u0026 Home Theather'],\n  ['id' =\u003e 2, 'name' =\u003e 'Tablets \u0026 E-Readers'],\n  ['id' =\u003e 3, 'name' =\u003e 'Computers', 'children' =\u003e [\n    ['id' =\u003e 4, 'name' =\u003e 'Laptops', 'children' =\u003e [\n      ['id' =\u003e 5, 'name' =\u003e 'PC Laptops'],\n      ['id' =\u003e 6, 'name' =\u003e 'Macbooks (Air/Pro)']\n    ]],\n    ['id' =\u003e 7, 'name' =\u003e 'Desktops'],\n    ['id' =\u003e 8, 'name' =\u003e 'Monitors']\n  ]],\n  ['id' =\u003e 9, 'name' =\u003e 'Cell Phones']\n];\n\nCategory::buildTree($categories) // =\u003e true\n```\n\nAfter that, we may just update the hierarchy as needed:\n\n```php\n$categories = [\n  ['id' =\u003e 1, 'name' =\u003e 'TV \u0026 Home Theather'],\n  ['id' =\u003e 2, 'name' =\u003e 'Tablets \u0026 E-Readers'],\n  ['id' =\u003e 3, 'name' =\u003e 'Computers', 'children' =\u003e [\n    ['id' =\u003e 4, 'name' =\u003e 'Laptops', 'children' =\u003e [\n      ['id' =\u003e 5, 'name' =\u003e 'PC Laptops'],\n      ['id' =\u003e 6, 'name' =\u003e 'Macbooks (Air/Pro)']\n    ]],\n    ['id' =\u003e 7, 'name' =\u003e 'Desktops', 'children' =\u003e [\n      // These will be created\n      ['name' =\u003e 'Towers Only'],\n      ['name' =\u003e 'Desktop Packages'],\n      ['name' =\u003e 'All-in-One Computers'],\n      ['name' =\u003e 'Gaming Desktops']\n    ]]\n    // This one, as it's not present, will be deleted\n    // ['id' =\u003e 8, 'name' =\u003e 'Monitors'],\n  ]],\n  ['id' =\u003e 9, 'name' =\u003e 'Cell Phones']\n];\n\nCategory::buildTree($categories); // =\u003e true\n```\n\nThe `makeTree` instance method works in a similar fashion. The only difference\nis that it will only perform operations on the *descendants* of the calling node instance.\n\nSo now imagine we already have the following hierarchy in the database:\n\n- Electronics\n- Health Fitness \u0026 Beaty\n- Small Appliances\n- Major Appliances\n\nIf we execute the following code:\n\n```php\n$children = [\n  ['name' =\u003e 'TV \u0026 Home Theather'],\n  ['name' =\u003e 'Tablets \u0026 E-Readers'],\n  ['name' =\u003e 'Computers', 'children' =\u003e [\n    ['name' =\u003e 'Laptops', 'children' =\u003e [\n      ['name' =\u003e 'PC Laptops'],\n      ['name' =\u003e 'Macbooks (Air/Pro)']\n    ]],\n    ['name' =\u003e 'Desktops'],\n    ['name' =\u003e 'Monitors']\n  ]],\n  ['name' =\u003e 'Cell Phones']\n];\n\n$electronics = Category::where('name', '=', 'Electronics')-\u003efirst();\n$electronics-\u003emakeTree($children); // =\u003e true\n```\n\nWould result in:\n\n- Electronics\n  + TV \u0026 Home Theater\n  + Tablets \u0026 E-Readers\n  + Computers\n    * Laptops\n      - PC Laptops\n      - Macbooks (Air/Pro)\n    * Desktops\n    * Monitors\n  + Cell Phones\n- Health Fitness \u0026 Beaty\n- Small Appliances\n- Major Appliances\n\nUpdating and deleting nodes from the subtree works the same way.\n\n\u003ca name=\"misc-utilities\"\u003e\u003c/a\u003e\n### Misc/Utility functions\n\n#### Node extraction query scopes\n\n provides some query scopes which may be used to extract (remove) selected nodes\nfrom the current results set.\n\n* `withoutNode(node)`: Extracts the specified node from the current results set.\n* `withoutSelf()`: Extracts itself from the current results set.\n* `withoutRoot()`: Extracts the current root node from the results set.\n\n```php\n$node = Category::where('name', '=', 'Some category I do not want to see.')-\u003efirst();\n\n$root = Category::where('name', '=', 'Old boooks')-\u003efirst();\nvar_dump($root-\u003edescendantsAndSelf()-\u003ewithoutNode($node)-\u003eget());\n... // \u003c- This result set will not contain $node\n```\n\n#### Get a nested list of column values\n\nThe `::getNestedList()` static method returns a key-value pair array indicating\na node's depth. Useful for silling `select` elements, etc.\n\nIt expects the column name to return, and optionally: the column\nto use for array keys (will use `id` if none supplied) and/or a separator:\n\n```php\npublic static function getNestedList($column, $key = null, $seperator = ' ');\n```\n\nAn example use case:\n\n```php\n$nestedList = Category::getNestedList('name');\n// $nestedList will contain an array like the following:\n// array(\n//   1 =\u003e 'Root 1',\n//   2 =\u003e ' Child 1',\n//   3 =\u003e ' Child 2',\n//   4 =\u003e '  Child 2.1',\n//   5 =\u003e ' Child 3',\n//   6 =\u003e 'Root 2'\n// );\n```\n\n\n\u003ca name=\"contributing\"\u003e\u003c/a\u003e\n## Contributing\n\nThinking of contributing? Maybe you've found some nasty bug? That's great news!\n\n1. Fork \u0026 clone the project: `git clone git@github.com:your-username/baum.git`.\n2. Run the tests and make sure that they pass with your setup: `phpunit`.\n3. Create your bugfix/feature branch and code away your changes. Add tests for your changes.\n4. Make sure all the tests still pass: `phpunit`.\n5. Push to your fork and submit new a pull request.\n\n\n## License\nThis fork from Baum laravel package i have just improved  for laravel 5.8 . \nthanks goes to Baum \nBaum is licensed under the terms of the [MIT License](http://opensource.org/licenses/MIT)\n(See LICENSE file for details).\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimajkumar%2Flaravel-binary-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimajkumar%2Flaravel-binary-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimajkumar%2Flaravel-binary-tree/lists"}