Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add name to laravel route

Tags:

php

laravel

blade

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

like image 744
Fnr Avatar asked Jan 08 '17 12:01

Fnr


1 Answers

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

like image 182
Alexey Mezenin Avatar answered Nov 08 '22 17:11

Alexey Mezenin