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 !
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 ] ) }}
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')) }}
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!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community