php Laravel 5.2 缺少 [Route: user.profile] [URI: user/{nickname}/profile] 的必需参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35259948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.2 Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile]
提问by Skel
I keep getting this error
我不断收到此错误
ErrorException in UrlGenerationException.php line 17:
When ever any page loads and I'm logged in.
当任何页面加载并且我登录时。
Here is what my nav looks like
这是我的导航的样子
@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
The problem I'm having is that the {{ route('user.profile') }} is not working??
我遇到的问题是 {{ route('user.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??
当我点击链接时 www.mydomain.com/User/SCRATK/profile 工作正常但页面不会因为这个错误加载??
Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile].
This is my routes file
这是我的路由文件
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']);
});
});
回答by The Alpha
You have to pass the route parameters to the route
method, for example:
您必须将路由参数传递给route
方法,例如:
<li><a href="{{ route('user.profile', $nickname) }}">Profile</a></li>
<li><a href="{{ route('user.settings', $nickname) }}">Settings</a></li>
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:
这是因为,两条路线{nickname}
在路线声明中都有一个。$nickname
例如,我已经使用过,但请确保将 更改$nickname
为适当的值/变量,例如,它可能类似于以下内容:
<li><a href="{{ route('user.settings', auth()->user()->nickname) }}">Settings</a></li>
回答by Diego Quispe
My Solution in laravel 5.2
我在 laravel 5.2 中的解决方案
{{ Form::open(['route' => ['votes.submit', $video->id], 'method' => 'POST']) }}
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-thumbs-up"></span> Votar
</button>
{{ Form::close() }}
My Routes File (under middleware)
我的路由文件(在中间件下)
Route::post('votar/{id}', [
'as' => 'votes.submit',
'uses' => 'VotesController@submit'
]);
Route::delete('votar/{id}', [
'as' => 'votes.destroy',
'uses' => 'VotesController@destroy'
]);
回答by ???' ??????
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']);
});
});