Laravel PHP artisan Route List command
Ideally, the php artisan route:list will display display the domain, method, URI, name, action and middleware for the routes it includes in the generated table.
Table to Contents
Now, what if I want to show a route list for a particular url, name or method?
Well, in this case, we can use some Term in Artisan Route List.
The syntax of Article Route list is-
php artisan route:list --TERM=VALUE
List of Terms
- —method : Filters the routes by method
- —name : Filters the routes by name
- —path= : Filters the routes by path (URI). None
- —reverse : Reverses the order the routes are displayed in the table
- -r : Reverses the order the routes are displayed in the table (shortcut to —reverse )
- —sort : The column to sort by. Accepted values are host, method, URI, name, action, or middleware
It will return the output as follows:
Some examples of the commands are:
# Filter the routes and display them in reverse order. php artisan route:list --method=GET --reverse # The following is equivalent to the previous example. php artisan route:list --method=GET -r # Filter the routes and sort the `name` column. php artisan route:list --method=GET --sort=name
Php artisan route list filter
Published on December 7, 2016
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:
It will generate a table similar to the following output (the exact table entries will depend on 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 appearing in the options name. Replace with the value to filter by when running the command.
Option Name | Description | Default Value |
---|---|---|
—method= | Filters the routes by method. | None |
—name= | Filters the routes by name. | None |
—path= | 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
Internally routes are filtered by checking to see if the search 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:
This same process can be repeated for the —method and —path options:
1# Filter the route list by URI.2php artisan route:list --path=account3 4# Filter the route list by method.5php artisan route:list --method=GET
The filters can be combined; results will be aggregated using «and» logic. The following command:
1php artisan route:list --path=account --method=GET
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 --reverse3 4# The following is equivalent to the previous example.5php artisan route:list --method=GET -r6 7# Filter the routes and sort `name` column.8php artisan route:list --method=GET --sort=name