PHPackages                             btb/closure-table - 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. btb/closure-table

ActiveLibrary

btb/closure-table
=================

A closure table tree package for laravel eloquent

0138PHP

Since Nov 6Pushed 1y agoCompare

[ Source](https://github.com/fast-oopdev/closure-table)[ Packagist](https://packagist.org/packages/btb/closure-table)[ RSS](/packages/btb-closure-table/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

About
-----

[](#about)

优雅的树形数据结构管理包,基于`Closure Table`模式设计.

Features
--------

[](#features)

- 优雅的树形数据设计模式
- 最少的数据库查询
- 一个Eloquent Trait简单操作
- 完善的树形结构操作方法
- 支持生成树形数据
- 支持多个根存在
- 支持节点/树修复
- 支持软删除
- 支持mogodb
- ...

依赖
--

[](#依赖)

- php &gt; 5.6.0
- laravel ~5.0|~6.0|~7.0|~8.0
- mysql &gt; 5.1.0|mogodb

关于`Closure Table`
-----------------

[](#关于closure-table)

> Closure table is a simple and elegant way of storing and querying hierarchical data in any RDBMS. By hierarchical data we mean a set of data that has some parent – child relationship among them. We use the word ‘tree’ instead of hierarchies commonly. As an example we may take the relationships between geographic locations like ‘Countries’, ‘States/ Province’, ‘Districts/ Cities’ etc.

`Closure Table`将树中每个节点与其后代节点的关系存储在数据库中, 这将需要一个存储节点关系的表`xxx_closure`.

例如一个菜单表`menus`:

idnameparent1A02AA13AB14AAA25ABA36ABAA5一个基本的`closure`表包含`ancestor`,`descendant`,`distance`3个字段,如:

ancestordescendantdistance110121131142152163220241330351362440550561660这个表记录了每个节点之间的关系,并且还记录了一条自身的关联,如：`1,1,0`.

使用
--

[](#使用)

`ClosureTable`提供了大量方法操作树结构.

### 影响树结构的方法

[](#影响树结构的方法)

```
