Add name to laravel route
Asked Answered
R

2

7

I've got a route defined as:

Route::get('/novanoticia', 'HomeController@getNovaNoticia');

When I run php artisan route:list it shows nothing on the name column. How to add a name to the route in such a way that I can later call it just by its name like: href="{{ route('route_name', $routeparam) }}?

Or will I have to redefine the route? Thanks in advance

Runion answered 8/1, 2017 at 12:50 Comment(0)
M
17

Option 1

Route::get('/novanoticia', 'HomeController@getNovaNoticia')->name('route_name');

Option 2

Route::get('/novanoticia', ['as' => 'route_name', 'uses' => 'HomeController@getNovaNoticia']);

https://laravel.com/docs/5.3/routing#named-routes

Merta answered 8/1, 2017 at 12:53 Comment(1)
how can i set my custom route name into the modules in vendor folder route as naming route?Trimerous
T
0

You can use the following step to name a route:

Route::get('/novanoticia', 'HomeController@getNovaNoticia')->name('route_name');

Also, you can use route naming conventions to name your routes so that you can recall them easily as below:

Route::get('/novanoticia', 'HomeController@getNovaNoticia')->name('controller_name.route_name');
Testify answered 22/2, 2021 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.