定制 bencolmer/nova-resource-hierarchy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bencolmer/nova-resource-hierarchy

Composer 安装命令:

composer require bencolmer/nova-resource-hierarchy

包简介

A Laravel Nova package that allows you to display and manage resource hierarchy in a tree view.

README 文档

README

Latest Version on Packagist

This package allows you to display and manage resource hierarchy in a tree view within Laravel Nova.

Resource Hierarchy

Features

Requirements

Installation Requirements

  • php: >=8.1
  • laravel/nova: ^5.0

Model Requirements

This package requires your model's database table to have the following columns:

Column Name Description
id The model's primary key column
parent_id A self-referencing foreign key column
rank A column recording the order of the hierarchy (optional - only required if enabling reordering)

You can customize the names of these columns - see customizing model keys below for details.

Installation

  1. Install this package via composer:
composer require bencolmer/nova-resource-hierarchy
  1. Register the tool with Laravel Nova via the tools method of the NovaServiceProvider.
// in app/Providers/NovaServiceProvider.php

use BenColmer\NovaResourceHierarchy\ResourceHierarchy;

// ...

public function tools()
{
    return [
        // ...

        ResourceHierarchy::make(\App\Nova\MyResource::class),
    ];
}

Next, take a look through the available configuration options.

Configuration

Once you have registered the tool in Nova, you have several configuration options available:

Customizing Model Keys

Set the ID, Parent ID, and order column (optional) names for the underlying model of a resource.

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->keyNames('idColumnName', 'parentIdColumnName', 'orderColumnName')
    ];
}

Enable Reordering

Enables reordering of the resource hierarchy (this functionality is disabled by default).

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->enableReordering()
    ];
}

Maximum Depth

Set the maximum hierarchy depth.

By default, the maximum depth is 10.

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->maxDepth(3)
    ];
}

Available Actions

You can control which actions (Create, View, Update, and Delete) are available.

By default, the Create, View, Update, and Delete actions are available. These actions are protected by authorization policies.

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->actions(['create', 'view', 'update', 'delete'])
    ];
}

Menu Entry

You can customize the menu entry title/icon:

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->menuTitle('This will be the menu title')
+           ->menuIcon('globe-alt')
    ];
}

Alternatively, you can hide the menu entry entirely:

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->hideMenu()
    ];
}

Page Title/Description

You can customize the title of the page and set a description.

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->pageTitle('Manage Hierarchy')
+           ->pageDescription('Manage the resource hierarchy below.')
    ];
}

Item Title

You can customize the title of each item displayed in the hierarchy.

By default, the resource title will be displayed.

use Illuminate\Database\Eloquent\Model;

// ...

public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->formatItemTitle(fn(Model $item) => implode(' - ', ([$item->id, $item->name])))
    ];
}

Authorization

This package uses Laravel's authorization policies to check a user's Create / View / Update / Delete permissions.

You can also define one further authorization method to control whether a user is authorized to reorder the resource hierarchy:

  1. Apply the AuthorizesHierarchy trait to your Nova resource:
// in app/Nova/MyResource.php

+ use BenColmer\NovaResourceHierarchy\Traits\AuthorizesHierarchy;

// ...

class MyResource extends Resource
{
+    use AuthorizesHierarchy;

    // ...
}
  1. Define a reorderHierarchy method on your Policy class:
// in app/Policies/MyResourcePolicy.php

// ...

class MyResourcePolicy
{
+    /**
+     * Determine whether the user can reorder the hierarchy.
+     */
+    public function reorderHierarchy(User $user): bool
+    {
+        return true; // check if the user is authorized
+    }

    // ...
}

Localization & Message Customization

The package translation files can be published using the following command:

php artisan vendor:publish --provider="BenColmer\NovaResourceHierarchy\ToolServiceProvider" --tag=translations

You can then edit these files to customize the messages as required.

Credits

License

Nova Resource Hierarchy is open-sourced software licensed under the MIT license.

bencolmer/nova-resource-hierarchy 适用场景与选型建议

bencolmer/nova-resource-hierarchy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 217 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「tree」 「nova」 「laravel」 「resource」 「hierarchy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 bencolmer/nova-resource-hierarchy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-12