Created
September 17, 2014 11:43
-
-
Save brihter/359111d0ac96c3b7d9d4 to your computer and use it in GitHub Desktop.
Call Laravel's controller actions automatically, no setup required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/routes.php | |
Route::get('/{controller}/{action?}/{params?}', function($controller, $action = 'index', $params = '') | |
{ | |
// controller | |
$controller = strtolower($controller); | |
$controller = ucfirst($controller); | |
$controller .= 'Controller'; | |
// params | |
$args = array(); | |
if (strlen($params) > 0) { | |
$args = explode('/', $params); | |
} | |
// go | |
$controllerInstance = App::make($controller); | |
$reflectionMethod = new ReflectionMethod($controller, $action); | |
$reflectionMethod->invokeArgs($controllerInstance, $args); | |
})->where('params','.*'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment