Skip to content

Commit

Permalink
Add action filter to route:list (#54135)
Browse files Browse the repository at this point in the history
* Add action filter to route:list

* Correct formatting

* Update RouteListCommand.php

---------

Co-authored-by: micce <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent ceaedb4 commit e0a81ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) ||
Expand Down Expand Up @@ -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'],
Expand Down
21 changes: 21 additions & 0 deletions tests/Testing/Console/RouteListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit e0a81ee

Please sign in to comment.