Reputation: 346
How do I add username to url?
Example: www.domain.com/feeds/username
I want to add username to every route url.
::Route::
Route::get('feeds', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));
::Controller::
class FeedsController extends BaseController {
public function getFeedsPage() {
return View::make('feeds.index');
}
}
Thanks in advance.
Michael.
Upvotes: 2
Views: 465
Reputation: 146201
You may try this, declare the route like this (Notice {username}
):
Route::get('feeds/{username}', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));
Declare the class
:
class FeedsController extends BaseController {
// Use a parameter to receive the username
public function getFeedsPage($username) {
// You may access the username passed via route
// inside this method using $username variable
return View::make('feeds.index')->with('username', $username);
}
}
Now you may use a URI
like these:
www.domain.com/feeds/username1
www.domain.com/feeds/michaelsangma
Upvotes: 2