From f9c3a9523446e306d87a528a39e949097141f0db Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Tue, 29 Oct 2019 21:20:02 +0100 Subject: [PATCH] Filter Route from usage:route command too --- src/Console/Commands/UsageRouteCommand.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Console/Commands/UsageRouteCommand.php b/src/Console/Commands/UsageRouteCommand.php index ef108de..7488976 100644 --- a/src/Console/Commands/UsageRouteCommand.php +++ b/src/Console/Commands/UsageRouteCommand.php @@ -17,7 +17,20 @@ class UsageRouteCommand extends RouteListCommand protected function getRoutes() { - $routes = $this->splitRoutesByMethods(parent::getRoutes()); + $regex = config('route-usage.excluding-regex') + ['name' => false, 'uri' => false]; + + $routes = $this->splitRoutesByMethods(parent::getRoutes()) + ->filter(function ($route) use ($regex) { + if ( + 'OPTIONS' == $route['method'] || + $regex['name'] && preg_match($regex['name'], $route['name']) || + $regex['uri'] && preg_match($regex['uri'], $route['uri']) + ) { + return false; + } + + return true; + }); // TODO: sort by updated_at and group by method+path $routeUsage = RouteUsage::all()->mapWithKeys(function ($r) {