From e0a81eed8a68937ecf4b092500a4a68717e0f4c1 Mon Sep 17 00:00:00 2001 From: miccehedin Date: Thu, 9 Jan 2025 21:56:29 +0100 Subject: [PATCH] Add action filter to route:list (#54135) * Add action filter to route:list * Correct formatting * Update RouteListCommand.php --------- Co-authored-by: micce Co-authored-by: Taylor Otwell --- .../Foundation/Console/RouteListCommand.php | 2 ++ .../Testing/Console/RouteListCommandTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 6cb010bf452e..4254a18c8129 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -264,6 +264,7 @@ protected function isFrameworkController(Route $route) protected function filterRoute(array $route) { if (($this->option('name') && ! Str::contains((string) $route['name'], $this->option('name'))) || + ($this->option('action') && isset($route['action']) && is_string($route['action']) && ! Str::contains($route['action'], $this->option('action'))) || ($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'))) || @@ -496,6 +497,7 @@ protected function getOptions() return [ ['json', null, InputOption::VALUE_NONE, 'Output the route list as JSON'], ['method', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by method'], + ['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'], ['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'], diff --git a/tests/Testing/Console/RouteListCommandTest.php b/tests/Testing/Console/RouteListCommandTest.php index e75072f7f20d..61723bb9bce1 100644 --- a/tests/Testing/Console/RouteListCommandTest.php +++ b/tests/Testing/Console/RouteListCommandTest.php @@ -119,6 +119,27 @@ public function testRouteCanBeFilteredByName() ->expectsOutput(''); } + public function testRouteCanBeFilteredByAction() + { + $this->withoutDeprecationHandling(); + + $this->router->get('/', function () { + // + }); + $this->router->get('foo/{user}', [FooController::class, 'show']); + + $this->artisan(RouteListCommand::class, ['--action' => 'FooController']) + ->assertSuccessful() + ->expectsOutput('') + ->expectsOutput( + ' GET|HEAD foo/{user} Illuminate\Tests\Testing\Console\FooController@show' + )->expectsOutput('') + ->expectsOutput( + ' Showing [1] routes' + ) + ->expectsOutput(''); + } + public function testDisplayRoutesExceptVendor() { $this->router->get('foo/{user}', [FooController::class, 'show']);