Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: redirect from controller to named route with prams in URL

Tags:

php

laravel

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?

like image 406
Kris Avatar asked Jan 12 '14 19:01

Kris


People also ask

How do I redirect a route in Laravel?

Laravel offers an easy way to redirect a user to a specific page. By using the redirect() helper you can easily create a redirect like the following: return redirect('/home'); This will redirect the user to the /home page of your app.


2 Answers

In Laravel 5, you can use the helper methods:

return redirect()->route('route.name', [$param]); 
like image 181
Marwan Avatar answered Sep 20 '22 17:09

Marwan


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.

like image 23
Altrim Avatar answered Sep 20 '22 17:09

Altrim