rur2641 rur2641 - 1 year ago 70
PHP Question

How to redirect with wildcard in route

How to redirect with a variable in the route:

$id = 8;
return redirect('/userpage/{$id}');

The route:

Route::get('/userpage/{id}', 'UserController@userpage');

The controller:

public function userpage($id)
return $id;

This displays {$id}.

Answer Source

Just append the id to the url.

return redirect('/userpage/' . $id);

Or using double quoted strings

return redirect("/userpage/{$id}");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download