Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-route a laravel call internally (without redirect)?

In laravel, a given url is routed to a specific controller method. Inside that method, I want to return the response as if the user has visited a different route. I can do this like so:

return App::make('OtherController')->otherMethod();

However, that depends on my hardcoding the class and method names I want to send them to. I would prefer, to send them to another controller identified by the name of the route, rather than the name of the controller class. How can I do that?

One possibility is to return Redirect::route($otherRoute), except that a) this is an actual redirect, which means it adds to the page load time and replaces the url they see, and b) it makes it hard to transfer POST data. So, I don't want to do that.

How can I call a controller, knowing only the name of the route it is linked to?

like image 858
Benubird Avatar asked Jun 19 '15 08:06

Benubird


1 Answers

As @Mruf said, you could try:

return \Route::dispatch(\Request::create($otherRoute, 'GET')); 
like image 95
rap-2-h Avatar answered Nov 09 '22 10:11

rap-2-h