简体   繁体   中英

Laravel Spatie Laravel-Navigation Route Error

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 :

  1. Install the plugin with composer

  2. add the plugin to the config/app.php provider

    App\Providers\NavigationProvider::class,

  3. Add the alias in the config/app.php aliases

    'Navigation' => Spatie\Navigation\NavigationServiceProvider::class,

  4. From what I understand I create a new provider

    php artisan make:provider NavigationProvider

  5. Inside the provider I add to the top

    use Spatie\Navigation\Navigation;

  6. 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.

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() );
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM