How to get a list of registered route paths in Laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Extracting Registered Route Paths in Laravel - A Comprehensive Guide Body:

As a senior developer working on Laravel projects, you may encounter situations where you need to retrieve the list of registered routes and their paths to process, analyze or manipulate them. This blog post aims to provide a comprehensive solution for accessing this information efficiently.

The primary approach for gaining access to this data is through the use of route models. In Laravel 5+ versions, you can define a closure within your model's route() method that provides the functionality needed. Here's how you would do it:

```php // App/Models/Post.php class Post extends Model { public function route(Laravel\Routing\Route $route) { // Code to handle the route logic goes here such as checking permissions or logging access return [ '/post' => 'App\Http\Controllers\PostController@index', '/post/create' => 'App\Http\Controllers\PostController@create', '/post/{id}' => 'App\Http\Controllers\PostController@show', // Add more routes as needed ]; } } ```

In this example, we define a route function for the Post model that returns an array with all registered paths and their corresponding controllers. This approach is more flexible than directly accessing private properties of Laravel's RouteCollection class.

As mentioned earlier, there are other methods to achieve this goal in previous Laravel versions like 4.x. One such possibility involves using the Route::getRoutes() method. However, as you have already noticed, we do not directly access its protected properties. Instead, we can serialize the object and then use the unserialize function on it.

```php $routes = unserialize(base64_decode(json_encode(Route::getRoutes()->toArray(), JSON_THROW_ON_ERROR))); $paths = array_column($routes, 'uri'); ```

Here, we serialize the RouteCollection object, base64-encode its serialized content, then use JSON's toArray() method to convert it back to a regular PHP array. Finally, we extract the paths using array_column() and return an array containing all routes paths.

To summarize, when working with Laravel routes, there are multiple methods to retrieve registered path information. The most straightforward approach is to define route() functions in your model classes, providing you with a clean way to manage and manipulate the data as needed. Older versions may require some workarounds, but in any case, your goal of getting a list of registered routes paths can be achieved.

As always, remember to practice safe coding practices such as using strong passwords, securing sensitive information, and following best practices for Laravel development. For more resources on this topic, you can check our blog posts at Laravel Company's Blog or reach out to our experienced Laravel developers who are available to answer your questions.

Conclusion

In conclusion, getting a list of registered route paths in Laravel can be done using different methods. One preferred approach is defining a route() function in model classes, while another involves a series of workarounds for older versions. No matter which method you choose, always prioritize security and best coding practices to ensure optimal performance and maintainability of your applications.