Support the ongoing development of Laravel.io →
posted 11 years ago
Testing

That's my route:

Route::get('/admin/dashboard/{username}', array(
    'as' => 'get-admin-dashboard',
    'uses' => 'AdminController@getAdminDashboard'
));

and that's my method:

public function getAdminDashboard($username) {
    $user = User::where('username', '=', $username);
        
    if($user->count()) {
        $user = $user->first();
        return  View::make('admin.dashboard')
                  ->with('user', $user);
    }
        
    return App::abort(404);
        
}

how you can see I want to have this path, for example: 'admin/dashboard/billy'. But how do I create this link ? I've tried to use only the name of this route which is: {{ URL::route('get-admin-dashboard') }}, but I got: 'admin/dashboard/{username}' I've alsow tried this: {{ URL::route('get-admin-dashboard').'/'.Auth::user()->username }} and in this case I've got this: 'admin/dashboard/{username}/billy' .Can someone tell me how do I create this link ? Thanks a lot !

Last updated 3 years ago.
0

If you're using URL::route() the second argument is an optional array for parameters, try something like this:

{{ URL::route( 'get-admin-dashboard', [ 'username' => Auth::user()->username ] ) }}
Last updated 3 years ago.
0

URL::route('get-admin-dashboard', array('username-here')) should do you. Just put all possible params in that array (in your case just one param, of course).

If you're trying to make a link you should probably use {{ link_to_route('get-admin-dashboard', 'Dashboard', array('username-here')) }} or {{ HTML::linkRoute('get-admin-dashboard', 'Dashboard', array('username-here')) }}

Last updated 3 years ago.
0

You have the array outside the function. Change it to:

<li><a href="<?php echo URL::route('get-admin-dashboard', array( 'username' => Auth::user()->username) ); ?>">Profile</a></li>

You could even make it cleaner using the linkRoute method off the HTML facade:

<li>
{{ HTML::linkRoute( 'get-admin-dashboard', 'Profile', array( 'username' => Auth::user()->username )  }}
</li>

Edit: Noticed you removed your last post and marked the thread as solved, so guess you figured it out :) Happy coding!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jacko1998 jacko1998 Joined 2 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.