Laravel Artisan Route Command: The route:list Command

3 min read

The route:list command can be used to show a list of all the registered routes for the application. This command will display the domain, method, URI, name, action and middleware for the routes it includes in the generated table.

The following example demonstrates how to use the command without any options:

1php artisan route:list
2

It will generate a table similar to the following output (the exact table entries will depend on the registered routes).

The registered routes

The routes table can be filtered by using the various different options that the command defines. The following table lists and describes each of the various options the command supports. Some of the options support user supplied filters, which are denoted by the <TERM> appearing in the options name. Replace <TERM> with the value to filter by when running the command.

Option Name Description Default Value
--method=<TERM> Filters the routes by method. None
--name=<TERM> Filters the routes by name. None
--path=<TERM> Filters the routes by path (URI). None
--reverse Reverses the order the routes are displayed in the table. None
-r Reverses the order the routes are displayed in the table (shortcut to --reverse). None
--sort The column to sort by. Accepted values are host, method, uri, name, action or middleware. uri

The following examples demonstrate the effects of the various different options.

Filtering the routes by name:

1# Filter the route list by name.
2php artisan route:list --name=account
3

Internally routes are filtered by checking to see if the search <TERM> simply exists within the route's name, path or method; filtering does not support wildcard characters.

After the above command has executed, a table will be generated that only contains routes that have account in the name column:

Filtered routes

This same process can be repeated for the --method and --path options:

1# Filter the route list by URI.
2php artisan route:list --path=account
3
4# Filter the route list by method.
5php artisan route:list --method=GET
6

The filters can be combined; results will be aggregated using "and" logic. The following command:

1php artisan route:list --path=account --method=GET
2

can be interpreted as "find all routes that contain account in the URI and contain GET in the method."

The following examples demonstrate how to call the command with the various other options:

1# Filter the routes and display them in reverse order.
2php artisan route:list --method=GET --reverse
3
4# The following is equivalent to the previous example.
5php artisan route:list --method=GET -r
6
7# Filter the routes and sort `name` column.
8php artisan route:list --method=GET --sort=name
9

Comments

There are no comments. Be the first to comment!

Up next