Sayakiss Sayakiss - 1 month ago 5x
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?


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.