Laravel error: Missing required parameters for route
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??
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].
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']);
});
});
Solution 1:
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>
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>
Solution 2:
My Solution in 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'
]);