From 7b93179723ff602aab4544e3360782fe49b5e661 Mon Sep 17 00:00:00 2001 From: Jason McCreary Date: Sun, 16 Nov 2025 14:22:33 -0500 Subject: [PATCH 1/2] Add `--middleware` filter to `route:list` --- src/Illuminate/Foundation/Console/RouteListCommand.php | 2 ++ tests/Foundation/Console/RouteListCommandTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 36813d87d1a5..ca730cfcdc87 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -268,6 +268,7 @@ protected function filterRoute(array $route) ($this->option('path') && ! Str::contains($route['uri'], $this->option('path'))) || ($this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method')))) || ($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain'))) || + ($this->option('middleware') && ! Str::contains($route['middleware'], $this->option('middleware'))) || ($this->option('except-vendor') && $route['vendor']) || ($this->option('only-vendor') && ! $route['vendor'])) { return; @@ -500,6 +501,7 @@ protected function getOptions() ['action', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by action'], ['name', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by name'], ['domain', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by domain'], + ['middleware', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by middleware'], ['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'], ['except-path', null, InputOption::VALUE_OPTIONAL, 'Do not display the routes matching the given path pattern'], ['reverse', 'r', InputOption::VALUE_NONE, 'Reverse the ordering of the routes'], diff --git a/tests/Foundation/Console/RouteListCommandTest.php b/tests/Foundation/Console/RouteListCommandTest.php index a1a93fa155ee..8c7f7e1081f2 100644 --- a/tests/Foundation/Console/RouteListCommandTest.php +++ b/tests/Foundation/Console/RouteListCommandTest.php @@ -190,4 +190,14 @@ public function testMiddlewareGroupsExpandCorrectlySortedIfVeryVerbose() $this->assertJsonStringEqualsJsonString($expectedOrder, $output); } + + public function testFilterByMiddleware() + { + $this->app->call('route:list', ['--json' => true, '--middleware' => 'auth']); + $output = $this->app->output(); + + $expectedOrder = '[{"domain":null,"method":"GET|HEAD","uri":"example-group","name":null,"action":"Closure","middleware":["web","auth"]}]'; + + $this->assertJsonStringEqualsJsonString($expectedOrder, $output); + } } From 357ecef4ae56c5e215216ea81fe2d0026409f1c2 Mon Sep 17 00:00:00 2001 From: Jason McCreary Date: Sun, 16 Nov 2025 14:36:22 -0500 Subject: [PATCH 2/2] Use verbose for Windows test --- tests/Foundation/Console/RouteListCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Foundation/Console/RouteListCommandTest.php b/tests/Foundation/Console/RouteListCommandTest.php index 8c7f7e1081f2..edecbf3fcab9 100644 --- a/tests/Foundation/Console/RouteListCommandTest.php +++ b/tests/Foundation/Console/RouteListCommandTest.php @@ -193,7 +193,7 @@ public function testMiddlewareGroupsExpandCorrectlySortedIfVeryVerbose() public function testFilterByMiddleware() { - $this->app->call('route:list', ['--json' => true, '--middleware' => 'auth']); + $this->app->call('route:list', ['--json' => true, '-v' => true, '--middleware' => 'auth']); $output = $this->app->output(); $expectedOrder = '[{"domain":null,"method":"GET|HEAD","uri":"example-group","name":null,"action":"Closure","middleware":["web","auth"]}]';