A Nova tool to manage menus.
- PHP >= 7.4
- Laravel Nova >= 3.0
- Laravel Framework >= 7.0
NOTE: These instructions are for Laravel 7.x and 8.x. 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 :
@menu("slug-of-menu")
By default a fallback to app()->getLocale() is activated.
If you want force a specific slug with no fallback you can call :
@menu("slug-of-menu|no-locale-fallback")
You can override views with :
php artisan vendor:publish --provider="Novius\LaravelNovaMenu\LaravelNovaMenuServiceProvider" --tag="views"
linkable_objects
You can add dynamic routes to linkable_objects
array (in configuration file).
Example with App\Models\Foo
Model.
In this example we have a route defined as following :
Route::get('foo/{slug}', 'FooController@show')->name('foo.show');
First, you have to add the Model to laravel-nova-menu.php
config file.
return [
'linkable_objects'=> [
App\Models\Foo:class => 'foo.label', // foo.label is a translation key
],
...
];
Then, you have to implements Linkable
trait to the model.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Novius\LaravelNovaMenu\Traits\Linkable;
class Foo extends Model
{
use Linkable;
public function linkableUrl(): string
{
return route('foo.show', ['slug' => $this->slug]);
}
public function linkableTitle(): string
{
return $this->name;
}
}
linkable_routes
You can also add static routes to linkable_routes
array (in configuration file).
Example with a route with name home
.
return [
'linkable_objects'=> [
'contact' => 'contact.page', // contact.page is a translation key
],
...
];
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.