rur2641 rur2641 - 1 month ago 10
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

Just append the id to the url.

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

Or using double quoted strings

return redirect("/userpage/{$id}");