Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Allow sorting routes by precedence in artisan routes:list. #53706

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ protected function getRoutes()
return $this->getRouteInformation($route);
})->filter()->all();

$routes = $this->sortRoutes($this->option('sort'), $routes);
if (($sort = $this->option('sort')) !== null) {
$routes = $this->sortRoutes($sort, $routes);
} else {
$routes = $this->sortRoutes('uri', $routes);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option is by 'uri' by default, so it seems not needed, as it's never null. I added a test to be sure of it.


if ($this->option('reverse')) {
$routes = array_reverse($routes);
Expand Down Expand Up @@ -153,7 +157,7 @@ protected function getRouteInformation(Route $route)
*/
protected function sortRoutes($sort, array $routes)
{
if ($sort === 'precedence') {
if ($sort === 'definition') {
return $routes;
}

Expand Down Expand Up @@ -495,7 +499,7 @@ protected function getOptions()
['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'],
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware, precedence) to sort by', 'uri'],
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (domain, method, uri, name, action, middleware, definition) to sort by', 'uri'],
['except-vendor', null, InputOption::VALUE_NONE, 'Do not display routes defined by vendor packages'],
['only-vendor', null, InputOption::VALUE_NONE, 'Only display routes defined by vendor packages'],
];
Expand Down