Laravel: Get URL from routes BY NAME

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Laravel: Get URL from Routes BY NAME Introduction In modern web development, using Laravel has become increasingly popular due to its rich features and capabilities. One of the essential aspects of creating a website using this framework is routing. You can easily define routes and associate them with controller actions to handle requests. However, sometimes, you might need to get the URL for a specific route based on its name, instead of relying only on current_route() or request()->route(). Understanding Route Naming Conventions By default, Laravel provides automatic naming conventions for your routes. Take a look at this simple example:
Route::any('/hos', 'HospitalController@index')->name("hospital");
This route defines a GET request to the '/hos' path and maps it to the HospitalController@index method. The name() method here is used to assign a friendly name, "hospital," for this specific route. This naming convention allows easy identification of routes within your codebase or during debugging. Retrieving Route URLs Using Route Names Now, let's address the issue you're facing. Unfortunately, Laravel does not explicitly provide a function to get the URL for a route based on its name, but we can still achieve this using helper functions from the Illuminate/Routing package. Follow these steps to accomplish your goal: 1. First, you need to determine the named route that corresponds to the desired URL. You can either look up in your routes file or use Laravel's Route::getRoutes() method to retrieve all existing routes and find the one with the matching name. 2. Once you have a handle on the named route, you can use the action() helper function from Illuminate\Routing package to get the URL for that specific route. This function accepts a route name as its parameter and returns the corresponding URL. In your case:
use Illuminate\Routing\Route;

$route = Route::getRoutes()->findByName("hospital");
if($route) {
   $my_route_url = action($route);
} else {
    // Handle the case where there is no route with that name.
}
echo $my_route_url;
With this approach, you can obtain the URL for a Laravel route based on its name. While it might not be as straightforward as using predefined functions like Route::getCurrentRoute(), this method achieves your goal of accessing specific routes by their names efficiently. Conclusion In summary, although there is no built-in function in Laravel to directly retrieve a route URL based on its name, you can achieve the same result with some custom coding and utilizing available helper functions. Keep in mind that this approach might not be as clean or elegant as using predefined methods. However, if you insist on achieving your dream scenario, you now have an alternative way of doing it.