I suppouse You can - if You must - do sth like that:
Route::get('/{controller}/{method}', function($controller, $method) {
$name = "\App\Http\Controllers\\" . $controller . 'Controller';
$class = new $name();
return $class->{$method}();
});
or if You have static methods:
Route::get('/{controller}/{method}', function($controller, $method) {
return call_user_func(array("\App\Http\Controllers\\" . $controller . 'Controller', $method));
});
But I don't think this is a good idea.
This way You loose all 'power' of laravel routing (because this is just one route).
For example:
- You can't refer to choosen method by route name
- You can't attach middleware to specific routes etc.
It is always better to be more explicit.
At least You can use one of these:
Route::resource()
or
Rotute::controller()
In both cases You will need to define routes for each controller, though.
Examples:
Route::resource('photo', 'PhotoController');
and then follow method name convention in Your controller (index, create etc.).
More here: http://laravel.com/docs/5.0/controllers#restful-resource-controllers
Route::controller('users', 'UserController');
and then prefix Your controller method by http method like: public function getIndex()
More here: http://laravel.com/docs/5.0/controllers#implicit-controllers