Sayakiss Sayakiss - 1 year ago 46
PHP Question

What is the "routeName" in route() function of Laravel?

In official doc:

$url = route('routeName');

In my daily usage of Laravel, I always write route as:

Route::get('/', function () {
return view('main');

Route::get('/test', 'TestController@test');

There is no name of Route rules...

So what is the "routeName" in route() function of Laravel? Can anyone provide a example?

Answer Source

Well, it's route name. You can name your routes with name() method or with as option:

Route::get('user/profile', 'UserController@showProfile')->name('profile');

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

You can see a list of route names with php artisan route:list command.