Skip to content

Instantly share code, notes, and snippets.

@ahmadrosid
Created September 9, 2019 03:17
Show Gist options
  • Save ahmadrosid/5dfdb074f3ee8a79bd845dc1e1353bf5 to your computer and use it in GitHub Desktop.
Save ahmadrosid/5dfdb074f3ee8a79bd845dc1e1353bf5 to your computer and use it in GitHub Desktop.
<?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