Route::get('/', function () {
    return view('welcome');
});

Route::get('{controller}/{action}', function($controller, $action = 'index') {
    $ctr = app()->make('\App\Http\Controllers\\'.ucfirst($controller).'Controller');
    return $ctr->callAction($action, array());
});

Route::get('{controller}/{action}/{id}', function($controller, $action = 'index', $id = null) {
    $ctr = app()->make('\App\Http\Controllers\\'.ucfirst($controller).'Controller');
    return $ctr->callAction($action, array('id'=> $id));
});

 

More:

https://laracasts.com/discuss/channels/general-discussion/l5-calling-dynamic-controller-names

Advertisements