Skip to content

Commit fa96878

Browse files
Add --middleware filter to route:list (#57797)
* Add `--middleware` filter to `route:list` * Use verbose for Windows test
1 parent a6d9e4b commit fa96878

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Illuminate/Foundation/Console/RouteListCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ protected function filterRoute(array $route)
268268
($this->option('path') && ! Str::contains($route['uri'], $this->option('path'))) ||
269269
($this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method')))) ||
270270
($this->option('domain') && ! Str::contains((string) $route['domain'], $this->option('domain'))) ||
271+
($this->option('middleware') && ! Str::contains($route['middleware'], $this->option('middleware'))) ||
271272
($this->option('except-vendor') && $route['vendor']) ||
272273
($this->option('only-vendor') && ! $route['vendor'])) {
273274
return;
@@ -500,6 +501,7 @@ protected function getOptions()
500501
['action', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by action'],
501502
['name', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by name'],
502503
['domain', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by domain'],
504+
['middleware', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by middleware'],
503505
['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'],
504506
['except-path', null, InputOption::VALUE_OPTIONAL, 'Do not display the routes matching the given path pattern'],
505507
['reverse', 'r', InputOption::VALUE_NONE, 'Reverse the ordering of the routes'],

tests/Foundation/Console/RouteListCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ public function testMiddlewareGroupsExpandCorrectlySortedIfVeryVerbose()
190190

191191
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
192192
}
193+
194+
public function testFilterByMiddleware()
195+
{
196+
$this->app->call('route:list', ['--json' => true, '-v' => true, '--middleware' => 'auth']);
197+
$output = $this->app->output();
198+
199+
$expectedOrder = '[{"domain":null,"method":"GET|HEAD","uri":"example-group","name":null,"action":"Closure","middleware":["web","auth"]}]';
200+
201+
$this->assertJsonStringEqualsJsonString($expectedOrder, $output);
202+
}
193203
}

0 commit comments

Comments
 (0)