10

I want to visit a page like...

http://mysitelocaltion/user_name/user_id

This is just a virtual link, I have used a .htaccess -rewrite rule to internally pass "user_name" and "use_id" as get parameters for my actual page.

How do I achieve the same in Laravel?

Update: This shall help (documentation)

Route::get('user/(:any)/task/(:num)', function ($username, $task_number) {
    // $username will be replaced by the value of (:any)
    // $task_number will be replaced by the integer in place of (:num)
    $data = array(
        'username' => $username,
        'task' => $task_number
    );
    return View::make('tasks.for_user', $data);
});

2 Answers 2

13
Route::get('(:any)/(:any)', function($user_name, $user_id) {
    echo $user_name;
});

Great to see you using Laravel!

Sign up to request clarification or add additional context in comments.

1 Comment

These are basic questions, might I suggest you check out my tutorials at daylerees.com :)
1

You can add the following in your route

Route::get('user_name/{user_id}', 'YourControllerName@method_name');

In your controller you can access the value as follows

public function method_name(Request $request, $user_id){
    echo $user_id;
    $user = User::find($user_id);
    return view('view_name')->with('user', $user);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.