[php] Laravel 5.2 Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile]

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']);
});
});

This question is related to php laravel laravel-routing laravel-5.2

The answer is


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>

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']);
});
});

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'
]);

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to laravel-routing

Laravel 5.2 Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile] Laravel: How to Get Current Route Name? (v5 ... v7) Set session variable in laravel Laravel 5 - redirect to HTTPS How Can I Remove “public/index.php” in the URL Generated Laravel? Download files in laravel using Response::download Laravel Controller Subfolder routing My Routes are Returning a 404, How can I Fix Them?

Examples related to laravel-5.2

How to uninstall an older PHP version from centOS7 Extension gd is missing from your system - laravel composer Update How to fix error Base table or view not found: 1146 Table laravel relationship table? Setting selected option in laravel form How to clear Route Caching on server: Laravel 5.2.37 Where are logs located? Laravel 5.2 redirect back with success message getting error while updating Composer How to validate phone number in laravel 5.2? Laravel check if collection is empty