scolib / tree
tree
Installs: 1 030
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ~5.6|~7.0
- illuminate/support: 5.3.*||5.4.*
README
是一个将数据格式化为树形结构的类库
安装
执行命令:
composer require scolib/tree
或 在 composer.json 文件中:
"require": {
"scolib/tree": "^1.0"
}
并执行 composer update
使用
<?php namespace App\Repositories; use Sco\Tree\Traits\TreeTrait; class MyClass { use TreeTrait; // 自定义属性(可选) protected $treeNodeIdName = 'id'; protected $treeNodeParentIdName = 'parent_id'; protected $treeSpacer = ' '; protected $treeFirstIcon = ' │ '; protected $treeMiddleIcon = ' ├─ '; protected $treeLastIcon = ' └─ '; /** * 获取待处理的原始节点数据 * * 必须实现 * * return \Illuminate\Support\Collection */ public function getTreeAllNodes() { } }
可用方法
public function setAllNodes(Collection $nodes) public function getSubLevel($parentId) public function getDescendants($parentId, $depth = 0, $adds = '') public function getLayerOfDescendants($id) public function getSelf($id) public function getParent($id) public function getAncestors($id, $depth = 0)