Download the PHP package jiaxincui/closure-table without Composer

On this page you can find all versions of the php package jiaxincui/closure-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package closure-table

About

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

Features

依赖

3.0 版本进行了重大更新,加入了字符串ID (如uuid等) 的支持、使用了更安全的SQL语、更规范的方法签名等

3.0 版本更改了根节点的 parent 列,之前默认使用 0, 3.0版本默认使用 null, 如果你准备从3.0以下版本升级,需要更新你的数据库,使 parent 列默认为 'null'

laravel < 9.0 ,请使用 2.1.x 版本

关于 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:

id name parent
1 A null
2 AA 1
3 AB 1
4 AAA 2
5 ABA 3
6 ABAA 5

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

ancestor descendant distance
1 1 0
1 2 1
1 3 1
1 4 2
1 5 2
1 6 3
2 2 0
2 4 1
3 3 0
3 5 1
3 6 2
4 4 0
5 5 0
5 6 1
6 6 0

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

使用

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

影响树结构的方法

它监听了 created,updating,restored 事件,如果你使用了 create(),或对实例使用了 update(), restore() 它将自动维护树结构. 这意味着如果你正在修改 parent 列,它也会自动维护树结构.

获取数据的方法

生成树形数据的方法

提供多种方法生成树形数据,可从任意节点生成树

生成的树如下:

判断方法

删除操作

ClosureTable 监听了模型的 deleting 事件

删除(包括软删除)一条记录,这个操作将解除自身的所有关联,

并且其所有 children 会成为根(parent = 0),这意味着所有的 children 成立了自己的树.

请勿使用以下方法来删除模型

Menu::destroy(1);

Menu::where('id', 1)->delete()

因为这些操作不会触发deleting事件

支持软删除,软删除的 restore(), 会根据它的 parent 列的记录恢复至相应的位置,你不需要去关心 closure 表里的记录,它已经帮你做了.

结构维护

安装

示例:

  1. model里引入 trait Jiaxincui\ClosureTable\Traits\ClosureTable.

  2. (非必需)如果你想自定义关联表名和字段,可在model里定义以下属性:$closureTable,$ancestorColumn,$descendantColumn,$distanceColumn.

  3. (非必需)如果你想自定义parent字段,在model里定义属性$parentColumn.

    如下示例:

接下来,你就可以自由的使用ClosureTable带来的所有功能了.

License

MIT © JiaxinCui


All versions of closure-table with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
illuminate/database Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jiaxincui/closure-table contains the following files

Loading the files please wait ....