artisanweblab/nested-tree 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artisanweblab/nested-tree

Composer 安装命令:

composer require artisanweblab/nested-tree

包简介

Nested Tree package for Laravel

README 文档

README

The nested set model is an advanced technique for maintaining hierachies among models using parent_id, nest_left, nest_right, and nest_depth columns. To use a nested set model, apply the ArtisanWebLab\NestedTree\Database\Traits\NestedTreeTrait trait.

composer require artisanweblab/nested-tree
 $table->integer('parent_id')->nullable();
 $table->integer('nest_left')->nullable();
 $table->integer('nest_right')->nullable();
 $table->integer('nest_depth')->nullable();
use ArtisanWebLab\NestedTree\Database\Traits\NestedTreeTrait;

class Category extends Model
{
    use NestedTreeTrait;

    // You can change the column names used by declaring    
    const PARENT_ID = 'my_parent_column';
    const NEST_LEFT = 'my_left_column';
    const NEST_RIGHT = 'my_right_column';
    const NEST_DEPTH = 'my_depth_column';
}

Creating a root node

By default, all nodes are created as roots:

$root = Category::create(['name' => 'Root category']);

Alternatively, you may find yourself in the need of converting an existing node into a root node:

$node->makeRoot();

You may also nullify it's parent_id column which works the same as `makeRoot'.

$node->parent_id = null;
$node->save();

Inserting nodes

You can insert new nodes directly by the relation:

$child1 = $root->children()->create(['name' => 'Child 1']);

Or use the makeChildOf method for existing nodes:

$child2 = Category::create(['name' => 'Child 2']);
$child2->makeChildOf($root);

Deleting nodes

When a node is deleted with the delete method, all descendants of the node will also be deleted. Note that the delete model events will not be fired for the child models.

$child1->delete();

Getting the nesting level of a node

The getLevel method will return current nesting level, or depth, of a node.

// 0 when root
$node->getLevel()

Moving nodes around

There are several methods for moving nodes around:

  • moveLeft(): Find the left sibling and move to the left of it.
  • moveRight(): Find the right sibling and move to the right of it.
  • moveBefore($otherNode): Move to the node to the left of ...
  • moveAfter($otherNode): Move to the node to the right of ...
  • makeChildOf($otherNode): Make the node a child of ...
  • makeRoot(): Make current node a root node.

Copyright (c) 2014-2020 Responsiv Pty Ltd, October CMS

artisanweblab/nested-tree 适用场景与选型建议

artisanweblab/nested-tree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 artisanweblab/nested-tree 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 artisanweblab/nested-tree 我们能提供哪些服务?
定制开发 / 二次开发

基于 artisanweblab/nested-tree 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-21