A Nova tool to manage menus.
- PHP >= 8.1
- Laravel Nova >= 4.0
- Laravel Framework >= 9.0 | >= 10.0 | >= 11.0
NOTE: These instructions are for Laravel >= 9.0 and Laravel Nova 4.0. If you are using prior version, please see the previous version's docs.
composer require novius/laravel-nova-menu
Then, launch migrations
php artisan migrate
Some options that you can override are available.
php artisan vendor:publish --provider="Novius\LaravelNovaMenu\LaravelNovaMenuServiceProvider" --tag="config"
Run:
php artisan vendor:publish --provider="Novius\LaravelNovaMenu\LaravelNovaMenuServiceProvider" --tag="views"
You can display menu with :
<x-laravel-nova-menu::menu menu="slug-of-menu" />
You can also display menu by passing the model instance :
<x-laravel-nova-menu::menu :menu="Menu::find(1)" />
By default a fallback to app()->getLocale() is activated.
If you want force a specific slug with no fallback you can call :
<x-laravel-nova-menu::menu menu="slug-of-menu" :localeFallback="false" />
If you want to use a specific view you can call :
<x-laravel-nova-menu::menu menu="slug-of-menu" view="partial/menu" />
You can override views with :
php artisan vendor:publish --provider="Novius\LaravelNovaMenu\LaravelNovaMenuServiceProvider" --tag="views"
Laravel Nova Menu uses Laravel Linkable to manage linkable routes and models. Please read the documentation.
<?php
namespace App\Providers;
use Novius\LaravelNovaMenu\LaravelNovaMenuService;
class AppServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
/**
* @var LaravelNovaMenuService $menu
*/
$menu = $this->app->get('laravel-nova-menu');
$menu->setTreeUsing(function(Menu $menu, array $tree) {
// ... your actions on tree
return $tree;
});
}
}
<?php
namespace App\Providers;
use Novius\LaravelNovaMenu\LaravelNovaMenuService;
class AppServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
/**
* @var LaravelNovaMenuService $menu
*/
$menu = $this->app->get('laravel-nova-menu');
$menu->setBuildTreeUsing(function(Collection $items) {
// ... your actions to build tree as an array
return $tree;
});
}
}
Run php-cs with:
composer run-script lint
Contributions are welcome! Leave an issue on Github, or create a Pull Request.
This package is under GNU Affero General Public License v3 or (at your option) any later version.