Created
August 27, 2017 21:17
-
-
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.
This file contains 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\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