enchance enchance - 3 years ago 108
PHP Question

Laravel: Load method in another controller without changing the url

I have this route:

Route::controller('/', 'PearsController');
Is it possible in Laravel to get the PearsController to load a method from another controller so the URL doesn't change?

For example:

// route:
Route::controller('/', 'PearsController');

// controllers
class PearsController extends BaseController {

public function getAbc() {
// How do I load ApplesController@getSomething so I can split up
// my methods without changing the url? (retains domain.com/abc)


class ApplesController extends BaseController {

public function getSomething() {
echo 'It works!'


Answer Source

You can use (L3 only)


In L4 you can use

$request = Request::create('/apples', 'GET', array());
return Route::dispatch($request)->getContent();

In this case, you have to define a route for ApplesController, something like this

Route::get('/apples', 'ApplesController@getSomething'); // in routes.php

In the array() you can pass arguments if required.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download