Print Available Route in Laravel

Posted on

This is an article relates on the development of a web-based application using Laravel framework. It is about how to print the possible and available routes which can be used and executed to access certain pages using certain URL address.

To be able to print any available and possible URL address which is provided in the web-based application using Laravel as its framework, a built-in utility such as ‘artisan’ can be very useful to fullfil that purpose. Below is an attempt to do that :

root@hostname:/var/www/html/laravel-project# php artisan routes

                                                                  
  [Symfony\Component\Console\Exception\CommandNotFoundException]  
  Command "routes" is not defined.                                
  Did you mean one of these?                                      
      route:cache                                                 
      route:clear                                                 
      route:list                                                  
                                                                  

In the above output command, there are actually several possibilities which can be used and it will affect or functioning for different purpose.

For the above purpose which is printing the available and possible route of a web-based application developed using Laravel framework, below is the correct execution command :

php artisan route:list

This is an example on executing the above command :

root@hostname:/var/www/html/laravel-project# php artisan route:list
+--------+-----------+-----------------------------+--------------------+--------------------------------------------------------+--------------+
| Domain | Method    | URI                          | Name               | Action                                                 | Middleware   |
+--------+-----------+------------------------------+--------------------+--------------------------------------------------------+--------------+
|        | GET|HEAD  | /                            |                    | Closure                                                | web          |
|        | GET|HEAD  | api/user                     |                    | Closure                                                | api,auth:api |
|        | GET|HEAD  | app                          | app.index          | App\Http\Controllers\ApplicationController@index       | web          |
|        | POST      | app                          | app.store          | App\Http\Controllers\ApplicationController@store       | web          |
|        | GET|HEAD  | app/create                   | app.create         | App\Http\Controllers\ApplicationController@create      | web          |
|        | PUT|PATCH | app/{app}                    | app.update         | App\Http\Controllers\ApplicationController@update      | web          |
|        | DELETE    | app/{app}                    | app.destroy        | App\Http\Controllers\ApplicationController@destroy     | web          |
|        | GET|HEAD  | app/{app}                    | app.show           | App\Http\Controllers\ApplicationController@show        | web          |
|        | GET|HEAD  | app/{app}/edit               | app.edit           | App\Http\Controllers\ApplicationController@edit        | web          |
|        | POST      | user                         | user.store         | App\Http\Controllers\UserController@store              | web          |
|        | GET|HEAD  | user                         | user.index         | App\Http\Controllers\UserController@index              | web          |
|        | GET|HEAD  | user/create                  | user.create        | App\Http\Controllers\UserController@create             | web          |
|        | GET|HEAD  | user/{user}                  | user.show          | App\Http\Controllers\UserController@show               | web          |
|        | PUT|PATCH | user/{user}                  | user.update        | App\Http\Controllers\UserController@update             | web          |
|        | DELETE    | user/{user}                  | user.destroy       | App\Http\Controllers\UserController@destroy            | web          |
|        | GET|HEAD  | user/{user}/edit             | user.edit          | App\Http\Controllers\UserController@edit               | web          |
+--------+-----------+------------------------------+--------------------+--------------------------------------------------------+--------------+
root@hostname:/var/www/html/laravel-project# 

Depends on the definition of the routes which is configured in neither within a file located in App\Http\routes.php or routes\web.php depends on the Laravel’s version, the above output which is generated after executing the above command to print the available or possible routes will vary.

Modifying routes including adding, removing or changing those available and possible routes shown above can be done by editing the files which is in charge for it. Either App\Http\routes.php or routes\web.php depends on the Laravel’s version or maybe any other files configured for that purpose.

One thought on “Print Available Route in Laravel

Leave a Reply