PHPackages                             lyxxxh/lartree - 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. lyxxxh/lartree

ActiveLibrary

lyxxxh/lartree
==============

树结构生成

1.0.0(6y ago)071JavaScript

Since Jun 8Pushed 4y agoCompare

[ Source](https://github.com/lyxxg/lartree)[ Packagist](https://packagist.org/packages/lyxxxh/lartree)[ RSS](/packages/lyxxxh-lartree/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

### 介绍

[](#介绍)

高效生成系统树 用于无限级分类

例如：楼中楼评论 获取下级分类等

只会产生一个sql并且速度非常快

### 支持

[](#支持)

仅支持adjacency结构 例如(classify表id(儿子) pid(父亲) )

### 测试 (只统计生成树使用的时间)

[](#测试-只统计生成树使用的时间)

[![测试](https://camo.githubusercontent.com/9026be0c08b0d3b3e1a4eaeceb2c291565cc664501d28beed604fd3722d6a6e8/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f746573742e706e67)](https://camo.githubusercontent.com/9026be0c08b0d3b3e1a4eaeceb2c291565cc664501d28beed604fd3722d6a6e8/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f746573742e706e67)

数据量(条)时间(s)内存(m)7560.0220.8352560.0752.84112560.165.67488430.88324.631088431.8052.42### 傻瓜式一次次查询

[](#傻瓜式一次次查询)

[![傻瓜式](https://camo.githubusercontent.com/c4b4b222856f6583385f0c83151c9c78f793d9f909173862785ab155d1745da2/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f666f7273716c2e706e67)](https://camo.githubusercontent.com/c4b4b222856f6583385f0c83151c9c78f793d9f909173862785ab155d1745da2/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f666f7273716c2e706e67)

```
查询到1 where pid = 1
查询到2 where pid = 2
查询到3 where pid = 3

```

数据量(条)时间(s)内存(m)1460.722.816463.0110.84264613.3442.91### 安装

[](#安装)

1. composer require lyxxxh/lartree

#### 查看例子(不使用也可以)

[](#查看例子不使用也可以)

[![例子](https://camo.githubusercontent.com/4cd5b598232015efc9b4306628d37292fbb656d30f026994140a071ba73099c3/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f65782e706e67)](https://camo.githubusercontent.com/4cd5b598232015efc9b4306628d37292fbb656d30f026994140a071ba73099c3/68747470733a2f2f7878682d646f776e6c6f61642e63646e2e626365626f732e636f6d2f65782e706e67)

```
1.在app/config.php的providers添加
  Xxh\LarTree\LarTreeProvider::class
2. php artisan vendor:publish --provider="Xxh\LarTree\LarTreeProvider::class"
3. 导入user 下面附数据库 （我测试的数据库）

```

4. 打开/lar\_tree [600条sql](https://xxh-download.cdn.bcebos.com/600.sql)[4w条sql](https://xxh-download.cdn.bcebos.com/4w.sql)[10w条sql](https://xxh-download.cdn.bcebos.com/10w.sql)

#### 生成树使用方法(可参考vendor/lyxxxh/lartree/src/LarController.php)

[](#生成树使用方法可参考vendorlyxxxhlartreesrclarcontrollerphp)

```
//引入命名空间
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](https://learnku.com/docs/laravel-core-concept/5.5/trait/3025)

根据需求重写里面的所有方法(看源码)

例如获取文章的评论 你完全可以复制代码 然后重写setDataContainer($data)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2530d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fbda2846ce7576ecbef245263ab795e62a1ea4a31c6d58bfdea89e20194ec90?d=identicon)[lyxxg](/maintainers/lyxxg)

---

Top Contributors

[![lyxxxh](https://avatars.githubusercontent.com/u/35553218?v=4)](https://github.com/lyxxxh "lyxxxh (8 commits)")

### Embed Badge

![Health badge](/badges/lyxxxh-lartree/health.svg)

```
[![Health](https://phpackages.com/badges/lyxxxh-lartree/health.svg)](https://phpackages.com/packages/lyxxxh-lartree)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
