41

how can I redirect from my controller to a named route and include variables in the URL, e.g.

return Redirect::to('admin/articles/create/'.$article_type.'/'.$area_id.'/'.$area_type);

this works, but I think that I missed a shortcut or something?

raveren
  • 17,799
  • 12
  • 70
  • 83
Kris
  • 768
  • 1
  • 8
  • 19

4 Answers4

90

In Laravel 5, you can use the helper methods:

return redirect()->route('route.name', [$param]);
Avag Sargsyan
  • 2,437
  • 3
  • 28
  • 41
Marwan
  • 1,802
  • 2
  • 17
  • 22
18

You can use Redirect::route() to redirect to a named route and pass an array of parameters as the second argument

 Redirect::route('route.name',array('param1' => $param1,'param2' => $param2))

Hope this helps.

Altrim
  • 6,536
  • 4
  • 33
  • 36
9

In Laravel 9 you can use the to_route() helper function.

return to_route('route.name', [$param]);
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
5

You can try this :

return redirect()->route('profile', [$user]);

This can help also if you are trying to redirect user to a profile with the id.

Jouby
  • 2,196
  • 2
  • 21
  • 33