Laravel错误:缺少路线所需的参数 [英] Laravel error: Missing required parameters for route
问题描述
我不断收到此错误
ErrorException in UrlGenerationException.php line 17:
任何页面加载并且我都已登录.
When ever any page loads and I'm logged in.
这是我的导航样子
@if(Auth::guest())
<li><a href="{{ url('/login') }}">Log In</a></li>
<li><a href="{{ url('/register') }}">Sign Up</a></li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ Auth::user()->nickname }}<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{{ route('user.profile') }}">Profile</a></li>
<li><a href="{{ route('user.settings') }}">Settings</a></li>
<li><a href="{{ url('/logout') }}">Log Out</a></li>
</ul>
</li>
@endif
我遇到的问题是{{route('user.profile')}}无法正常工作?
The problem I'm having is that the {{ route('user.profile') }} is not working??
当我点击链接时,www.mydomain.com/User/SCRATK/profile可以正常工作,但由于该错误页面无法加载?
When i hit the link is www.mydomain.com/User/SCRATK/profile is works fine but the page wont load becuase of this error??
Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile].
这是我的路线文件
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/', ['as' => 'home', 'uses' => 'BaseController@index']);
Route::group(['namespace' => 'User', 'prefix' => 'user'], function(){
Route::get('{nickname}/settings', ['as' => 'user.settings', 'uses' => 'SettingsController@index']);
Route::get('{nickname}/profile', ['as' => 'user.profile', 'uses' => 'ProfileController@index']);
});
});
推荐答案
您必须将路由参数传递给 route
方法,例如:
You have to pass the route parameters to the route
method, for example:
<li><a href="{{ route('user.profile', $nickname) }}">Profile</a></li>
<li><a href="{{ route('user.settings', $nickname) }}">Settings</a></li>
这是因为,两个路由在路由声明中都有一个 {nickname}
.例如,我使用了 $ nickname
,但是请确保将 $ nickname
更改为适当的值/变量,例如,它可能类似于以下内容:
It's because, both routes have a {nickname}
in the route declaration. I've used $nickname
for example but make sure you change the $nickname
to appropriate value/variable, for example, it could be something like the following:
<li><a href="{{ route('user.settings', auth()->user()->nickname) }}">Settings</a></li>
这篇关于Laravel错误:缺少路线所需的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!