Reputation: 527
I'm trying to make the Spatie Laravel-Navitation plugins to work on my project in Laravel 9.1.0 Spatie Laravel Navigation
So far I did :
Install the plugin with composer
add the plugin to the config/app.php provider
App\Providers\NavigationProvider::class,
Add the alias in the config/app.php aliases
'Navigation' => Spatie\Navigation\NavigationServiceProvider::class,
From what I understand I create a new provider
php artisan make:provider NavigationProvider
Inside the provider I add to the top
use Spatie\Navigation\Navigation;
Inside the handle function I add this
app(Navigation::class) ->add('dashboard', route('dashboard'));
I have the following error since:
Route [dashboard] not defined.
In my routes/web.php I have the following route.
Route::get('/', function () {
return view('pages.dashboard');
})->name('dashboard');
Any Idea what I miss. Any tips also on how I will use this in the blade after making the route portion work.
Thank you for your help.
Upvotes: 1
Views: 407
Reputation: 527
I maybe found the issue but I'm not sure it's the most elegant way to do this.
In my controller boot function I did this :
$this->app->booted(function () {
app(Navigation::class)
->add('dashboard', route('dashboard'));
});
view()->composer('*',function($view) {
$view->with('navigation', app(Navigation::class)->tree() );
$view->with('breadcrumbs', app(Navigation::class)->breadcrumbs() );
});
Upvotes: 0