Laravel Named Route


Example

Named routes are used to generate a URL or redirects to a specific route. The advantage of using a named route is, if we change the URI of a route in future, we wouldn't need to change the URL or redirects pointing to that route if we are using a named route. But if the links were generated using the url [ eg. url('/admin/login')], then we would have to change everywhere where it is used.

Named routes are created using as array key

Route::get('login', ['as' => 'loginPage', 'uses' => 'LoginController@index']);

or using method name

Route::get('login', 'LoginController@index')->name('loginPage');

Generate URL using named route

To generate a url using the route's name

$url = route('loginPage');

If you are using the route name for redirection

$redirect = Redirect::route('loginPage');