Skip to content

Instantly share code, notes, and snippets.

@umanda
Created April 9, 2018 03:01
Show Gist options
  • Save umanda/5e03ae76f22e30ae127edf13facff031 to your computer and use it in GitHub Desktop.
Save umanda/5e03ae76f22e30ae127edf13facff031 to your computer and use it in GitHub Desktop.
Get all controller actions which registered to the route file in Laravel 5.*
$controllers = [];
$i=0;
foreach (Route::getRoutes()->getRoutes() as $route)
{
$action = $route->getAction();
if (array_key_exists('controller', $action))
{
// You can also use explode('@', $action['controller']); here
// to separate the class name from the method
$_action = explode('@',$action['controller']);
$_namespaces_chunks = explode('\\',$_action[0]);
$controllers[$i]['controller'] = end($_namespaces_chunks);
$controllers[$i]['action'] = end($_action);
$controllers[$i]['namespace'] = $action['controller'];
$controllers[$i]['route'] = $route;
}
$i++;
}
dump($controllers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment