In Laravel 3, you could call a controller using the Controller::call method, like so:
Controller::call('api.items@index', $params);
I looked through the Controller class in L4 and found this method which seems to replace the older method: callAction(). Though it isn't a static method and I couldn't get it to work. Probably not the right way to do it?
How can I do this in Laravel 4?
use App\Http\Controllers\UserController; Route::get('/user/{id}', [UserController::class, 'show']); When an incoming request matches the specified route URI, the show method on the App\Http\Controllers\UserController class will be invoked and the route parameters will be passed to the method.
Laravel gives you lots of other other options too i.e. event, jobs, model oberservers etc. If you have two controllers that need to perform the same functionality, then one option is to use a trait which you can then include in both controllers. But you should never need to transfer from one controller to another.
The pseudo-variable $this is available when a method is called from within an object context. $ this is a reference to the calling object.
You may use IoC.
Try this:
App::make($controller)->{$action}();
Eg:
App::make('HomeController')->getIndex();
and you may also give params:
App::make('HomeController')->getIndex($params);
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