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

staticcode's avatar

Route [login] not defined.

Hi guys, i used

php artisan make:auth

after that I removed everything and wrote my own stuff. I can add a user (register), delete and edit a user. I can log in and that works perfectly fine. The only problem I am facing now is that when I want to protect a route I get this error:

InvalidArgumentException Route [login] not defined.

I did this in my web.php file:

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

Can someone help me out on how to fix this?

P.S. I have this in my controller:

return view('auth/login');

and in my folder I have this:

resources/views/auth/login.blade.php

so that shouldnt be a problem either is it?

EDIT: Got it working by adding "->name('login')" to it. But now it keeps redirecting me to the login for some reason when I try to go to a route within the group that i added "auth" to.

0 likes
8 replies
lanatel's avatar

return view('auth.login');

It have to redirect you to the login page if you are not logged in. That is how the auth middleware works. Or what do you mean?

rin4ik's avatar

make name for your route

Route::get('/login', 'LoginController@method')->name('login');
rin4ik's avatar
rin4ik
Best Answer
Level 50

@staticcode are you using this?

Auth::routes();

run php artisan route:list and check do you have route with name login . middleware trying to redirect you to route named login but can't find

1 like
staticcode's avatar

Didnt add Auth::routes(); because I wrote my own :)

staticcode's avatar

Got a bit further... problem now is that while logging someone in I do this:

$credentials = $request->only('email', 'password');

Then on a other page when I print_r() my Auth:user() there is nothing there... how come there is nothing there?

mooseh's avatar

are you making sure you are using Auth in the controller?

example

<?php

namespace App\Http\Controllers;
use Auth;

also just as a quick note you can use the facade built in laravel and not use Auth

you can just do user() "from laravel 5.5 onwards i think?"

by the way dd is your best freind in laravel for debugging, if you want to find info use dd

example:


$user = user();

//this will die and print nicely the user data
dd($user);


staticcode's avatar

yeah just found out that on the page where I set the user, it exists. When I go to any other page it does not exist... very strange :/

No clue where to look now :(

Ill post my exact code tomorrow, maybe someone can help me out cause I am clueless at the moment.

Please or to participate in this conversation.