Skip to content

Instantly share code, notes, and snippets.

@xtrasmal
Created August 27, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtrasmal/8a5b40b6d01d01e03e439e310d3e2656 to your computer and use it in GitHub Desktop.
Save xtrasmal/8a5b40b6d01d01e03e439e310d3e2656 to your computer and use it in GitHub Desktop.
Laravel command to show all routes that do not have a ROLE middleware.
<?php namespace App\Console\Commands;
use Illuminate\Routing\Route;
use Illuminate\Foundation\Console\RouteListCommand;
class RouteRBAC extends RouteListCommand
{
/**
* {@inheritdoc}
*/
protected $name = 'route:rbac';
/**
* {@inheritdoc}
*/
protected $description = 'Table of all routes that need rbac';
/**
* {@inheritdoc}
*/
protected $headers = ['method', 'uri', 'name', 'controller', 'action', 'middleware'];
/**
* {@inheritdoc}
*/
protected function getRouteInformation(Route $route)
{
$actions = explode('@',$route->getActionName());
$middleware = implode(',',$route->middleware());
if(!strpos($middleware, 'role')) {
return $this->filterRoute([
'method' => implode('|', $route->methods()),
'uri' => $route->uri(),
'name' => is_string($route->getName()) ? "<fg=green>{$route->getName()}</>" : "-",
'controller' => isset($actions[0]) ? "<fg=cyan>{$actions[0]}</>" : "-",
'action' => isset($actions[1]) ? "<fg=red>{$actions[1]}</>" : "-",
'middleware' => $middleware
]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment