Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

Route [login] not defined

web.php

// Login

Route::get('/login', 'LoginController@index');
Route::post('/dologin','LoginController@doLogin');

header.blade.php

<li><a href="{{ url('service') }}">SERVICE</a></li>

When I clicked service I get this error:

Symfony\Component\Routing\Exception\RouteNotFoundException Route [login] not defined.

I already try:

// Login

Auth::routes();
Route::get('/login', 'LoginController@index')->name('login');
Route::post('/dologin','LoginController@doLogin');

ref: https://laracasts.com/discuss/channels/laravel/route-login-not-defined

This time, when I clicked service it carries me to the login page, which is wrong. Any clue why?

0 likes
11 replies
douglasakula's avatar

Could you run php artisan route:list to see the list of routes within your application and confirm its as expected.

ftiersch's avatar

Your service route is protected by authentication. So if you click it and you are not authenticated it will automatically redirect you to the login page.

1 like
davy_yg's avatar
Level 27

I have two service routes:

Route::get('/service', 'FPController@services');

Route::group(['middleware' => ['auth']], function () {

    Route::get('/service', 'PageController@service');

});

Am I not allowed two have 2 service routes with the same name? The first one is for frontend page controller and the next is service admin page to edit the content and you have to login first before using it.

ftiersch's avatar

No you can't do that. Laravel looks through your routes one by one and calls the first one that matches the given URL. Everything else will be ignored. So if you rename one of them your problem should go away :)

davy_yg's avatar
Level 27

Okay it works but I wonder you have to:

Auth::routes();
Route::get('/login', 'LoginController@index')->name('login');

What is auth:routes() is for?

Why should you name this: name('login')

The does disappeared and only shows the login page when I try to access the admin routes.

1 like
ftiersch's avatar

Auth::routes() defines the default laravel authentication routes if you have them installed. There should actually be a 'login' route in there already.

And the default logic is it will redirect you to a route named "login" if you try to access a route thats protected while you are not logged in. You can check the Authenticate middleware and change that name.

Desmond3376's avatar
Level 1

you getting that error because you trying to access a route that is not defined when the user is not login

visit your app->middleware->Authenticate.php

then change this to your preferred route

return route('login');

7 likes
jserrano's avatar

I am getting this same error. I have a login page already but still getting the error.

Snapey's avatar

@jserrano 1 year old question :-(

They get this problem because they don't have a NAMED route

but anyway, solved a long time ago

1 like
taalai's avatar

It worked for my code. Thanks a lot.

Snapey's avatar

@desmond3376 1 year old question :-(

They get this problem because they don't have a NAMED route

but anyway, solved a long time ago

Please or to participate in this conversation.