PHP code example of bencolmer / nova-resource-hierarchy

1. Go to this page and download the library: Download bencolmer/nova-resource-hierarchy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bencolmer / nova-resource-hierarchy example snippets


// in app/Providers/NovaServiceProvider.php

use BenColmer\NovaResourceHierarchy\ResourceHierarchy;

// ...

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

        ResourceHierarchy::make(\App\Nova\MyResource::class),
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->keyNames('idColumnName', 'parentIdColumnName', 'orderColumnName')
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->enableReordering()
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->maxDepth(3)
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->actions(['create', 'view', 'update', 'delete'])
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->hideMenu()
    ];
}
diff
public function tools()
{
    return [
        ResourceHierarchy::make(\App\Nova\MyResource::class),
+           ->pageTitle('Manage Hierarchy')
+           ->pageDescription('Manage the resource hierarchy below.')
    ];
}
diff
use Illuminate\Database\Eloquent\Model;

// ...

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

// 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
+    }

    // ...
}
bash
php artisan vendor:publish --provider="BenColmer\NovaResourceHierarchy\ToolServiceProvider" --tag=translations