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
This package allows you to display and manage resource hierarchy in a tree view within Laravel Nova.
Features
- Drag-and-drop nesting and reordering
- A large number of configuration options
- Laravel Authorization support
- Localization support
Requirements
Installation Requirements
php: >=8.1laravel/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
- Install this package via composer:
composer require bencolmer/nova-resource-hierarchy
- Register the tool with Laravel Nova via the
toolsmethod of theNovaServiceProvider.
// 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:
- Apply the
AuthorizesHierarchytrait to your Nova resource:
// in app/Nova/MyResource.php + use BenColmer\NovaResourceHierarchy\Traits\AuthorizesHierarchy; // ... class MyResource extends Resource { + use AuthorizesHierarchy; // ... }
- Define a
reorderHierarchymethod 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bencolmer/nova-resource-hierarchy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
jsTree widget for yii2
A Laravel Nova package for publishable fields
Doctrine2 behavior traits - slowhop fork
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 217
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-12
