bencolmer / nova-resource-hierarchy
A Laravel Nova package that allows you to display and manage resource hierarchy in a tree view.
Requires
- php: >=8.1
- illuminate/support: ^10.0|^11.0|^12.0
- laravel/nova: ^5.0
Requires (Dev)
- laravel/nova-devtool: ^1.7
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2025-07-12 20:38:01 UTC
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.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
- Install this package via composer:
composer require bencolmer/nova-resource-hierarchy
- Register the tool with Laravel Nova via the
tools
method 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
AuthorizesHierarchy
trait to your Nova resource:
// in app/Nova/MyResource.php + use BenColmer\NovaResourceHierarchy\Traits\AuthorizesHierarchy; // ... class MyResource extends Resource { + use AuthorizesHierarchy; // ... }
- 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.