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?
As @Mruf said, you could try:
return \Route::dispatch(\Request::create($otherRoute, 'GET'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With