Created
September 9, 2019 03:17
-
-
Save ahmadrosid/5dfdb074f3ee8a79bd845dc1e1353bf5 to your computer and use it in GitHub Desktop.
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 | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class RoutesCommand extends Command { | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'route:list'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Display all registered routes.'; | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
global $app; | |
$routeCollection = $app->router->getRoutes(); | |
$rows = array(); | |
$x = 0; | |
foreach ($routeCollection as $route) { | |
if( !empty($route['action']['uses']) ) { | |
$data = $route['action']['uses']; | |
if (($pos = strpos($data, "@")) !== FALSE) { | |
$action = substr($data, $pos+1); | |
} | |
} else { | |
$action = 'Closure func'; | |
} | |
$rows[$x]['verb'] = $route['method']; | |
$rows[$x]['path'] = $route['uri']; | |
$rows[$x]['action'] = $action; | |
$x++; | |
} | |
$headers = array( 'Verb', 'Path', 'Action' ); | |
$this->table($headers, $rows); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment