[英]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我正在尝试让 Spatie Laravel-Navitation 插件在我的 Laravel 9.1.0 Spatie Laravel Navigation中的项目上工作
So far I did :到目前为止,我做到了:
Install the plugin with composer使用 composer 安装插件
add the plugin to the config/app.php provider将插件添加到 config/app.php 提供程序
App\Providers\NavigationProvider::class, App\Providers\NavigationProvider::class,
Add the alias in the config/app.php aliases在 config/app.php aliases 中添加别名
'Navigation' => Spatie\Navigation\NavigationServiceProvider::class, '导航' => Spatie\Navigation\NavigationServiceProvider::class,
From what I understand I create a new provider据我了解,我创建了一个新的提供者
php artisan make:provider NavigationProvider php artisan make:provider NavigationProvider
Inside the provider I add to the top在提供程序内部,我添加到顶部
use Spatie\Navigation\Navigation;使用 Spatie\Navigation\Navigation;
Inside the handle function I add this在句柄函数中我添加了这个
app(Navigation::class) ->add('dashboard', route('dashboard')); 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.在我的 routes/web.php 中,我有以下路线。
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() );
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.