lyxxxh / lartree
该包的最新版本(1.0.0)没有提供许可信息。
树结构生成
1.0.0
2019-06-07 23:01 UTC
This package is auto-updated.
Last update: 2024-09-25 15:59:34 UTC
README
介绍
高效生成系统树,用于无限级分类
例如:楼中楼评论,获取下级分类等
只会产生一个SQL并且速度非常快
支持
仅支持adjacency结构,例如(classify表id(儿子) pid(父亲) )
测试(只统计生成树使用的时间)
傻瓜式一次次查询
查询到1 where pid = 1
查询到2 where pid = 2
查询到3 where pid = 3
安装
- composer require lyxxxh/lartree
查看例子(不使用也可以)
1.在app/config.php的providers添加
Xxh\LarTree\LarTreeProvider::class
2. php artisan vendor:publish --provider="Xxh\LarTree\LarTreeProvider::class"
3. 导入user 下面附数据库 (我测试的数据库)
生成树使用方法(可参考vendor/lyxxxh/lartree/src/LarController.php)
//引入命名空间
use Xxh\LarTree\Services\LarTreeServices;
class LarController extends Controller {
use LarTree; //使用LarTree
public function index()
{
//设置需要的字段 为了更快速 不设置也可以
$this->setField(['id','pid','name']);
//默认是id pid
// $this->setFatherSonName('子id','父id');
//设置表 把查询到的所有结果先存到$datas变量
$this->initTableConainer('users');
//最开始的父id
$data = $this->getTableTree(0);
dd($data);//获取树结构了
}
}
自定义
vendor/lyxxxh/lartree/src/LarTree.php使用trait
根据需求重写里面的所有方法(看源码)
例如获取文章的评论,你完全可以复制代码然后重写setDataContainer($data)