Created
April 9, 2018 03:01
-
-
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.*
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
$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