Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alpha's avatar

What is the use of Route Name?

Hello guys, good morning, afternoon and night~

What is the use of Route Name? as i read the RESTful resource it is located in the last colum of the table Route Name

I know that the path is the parameter that we can use to access the web http://localhost:8000/articles #articles

Action is to be referred to the path

and what about Route name? which part of the process do we used it for

0 likes
7 replies
mstnorris's avatar
Level 55

@alpha To give it a friendly name to refer to it, that's all.

Names Routes for use with things like the URL Helper Method.

Named routes allow you to conveniently generate URLs or redirects for a specific route. You may specify a name for a route using the as array key when defining the route:

Route::get('user/profile', ['as' => 'profile', function () {
    //
}]);

You may also specify route names for controller actions:

Route::get('user/profile', [
    'as' => 'profile', 'uses' => 'UserController@showProfile'
]);

So you can do things like:

Assigning it to a variable.

$url = route('profile');

When opening forms so it knows what route to POST to:

{!! Form::open('method' => 'POST', ['route' => 'profile']) !!}

This will generate a full link to the route http://yourdomain.dev/profile

{{ link_to_route('profile') !!}
3 likes
xsmalbil@icloud.com's avatar

For instance:

get('/admin/dashboard',                 ['as' => 'backend.dashboard',              'uses' => 'BackendController@dashboard']);

The route itself can change.

get('/cms/dashboard',                 ['as' => 'backend.dashboard',              'uses' => 'BackendController@dashboard']);

In either case.. if you use the named route to create a link in your templates, then you would not have to change it. It als helps as a shortcut, to remember better.

route('backend.dashboard');
3 likes
Kryptonit3's avatar

also to make it easier to change the uri should the need arise in the future so you don't have to go seek and find threw the views and controllers.

alpha's avatar

@mstnorris Thank you for the crystal clear explanation, Got it now

but what is the difference between

Route::get('articles',  ['as' => 'foo', 'uses' => 'ArticlesController@index']);
  • and
Rotue::get('articles', ['uses' => 'ArticlesController@index', 'as' => 'foo']);

and thanks everyone for the ansers ~

Kryptonit3's avatar

@alpha nothing, personal preference. From what I have seen though, people usually put the name before the controller.

1 like
mstnorris's avatar

@alpha as @Kryptonit3 says, nothing but I think it is more readable in your first example, like so:

Route::get('articles',  ['as' => 'foo', 'uses' => 'ArticlesController@index']);

Read as: "A GET request made to "articles" is referred to by "foo" uses ArticlesController@index.

1 like

Please or to participate in this conversation.