【发布时间】:2021-05-01 16:47:51
【问题描述】:
在包含我的路线的 web.php 中,我有以下路线:
Route::get('/profile', 'Profile\ProfileController@index');
哪些链接到我的配置文件控制器
我用
Route::get('/profile', 'Profile\ProfileController@index');
但是,当我导航到设置了此路由的页面时,我收到此错误
ErrorException (E_ERROR)
Route [profile] not defined. (View: D:\MAMP\htdocs\milestoneexp\resources\views\layouts\app.blade.php) (View: D:\MAMP\htdocs\milestoneexp\resources\views\layouts\app.blade.php)
但是,当我从路由切换到 URL 时,以下代码可以正常使用导航
<a class="dropdown-item" href="{{ url('profile') }}">{{ __('Profile') }}</a>
为什么 URL 有效但路由无效?我怎样才能让我的路线工作?
Laravel 5.8.35 版
【问题讨论】:
-
这不是导致错误的行...某处有一个
route('profile')调用 -
route() 函数仅用于调用具有与路由关联的名称的路由。在您的路由声明中,您没有为其指定名称,这就是 route() 函数不起作用的原因。您必须在 web.php 中的路由声明中添加“->name('profile')”以使其正常工作。