P
P
Programmir2018-04-09 20:16:47
Laravel
Programmir, 2018-04-09 20:16:47

Why might the route 'login' not defined error pop up?

In general, I started watching videos on laracasts, and there is an example of authorization, and I began to repeat it. I have a [email protected]() where a new user registers

$user = User::create([
            'name' => $request['name'],
            'email' => $request['email'], 
            ...
])

auth()->login($user);
    
$id = auth()->id();
    
return redirect()->route('home', ['id' => $id]);

There is a redirect to the user page /home/id. But an error pops up, like route login not defined. Moreover, if you refresh the page, the error disappears and everything is fine. But auth returns false, like the user is not authenticated, although a new user has signed up to the database. And since the user is not authenticated, then I can register a new user. I do it, and already errors, such as route login do not pop up. The new user is entered into the database and redirected to his page. and authindicates that the user is already authenticated. And that's why I can't register a new one. Then I log out using auth()->logout(). Registering a new user. But again an error occurs, like route login not defined. And if you refresh the page, then everything is fine, but the user is not authenticated. In general, again goes in the same circle. It turns out that when the user first writes, for some reason auth()->login() gives an error, but when the page is reloaded, the error disappears. And if you register a new user, then the error is gone. Apparently, somewhere some data is recorded, that before that, like he logged in. Is the registration correct? I just repeated the code from the video.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Koteezy, 2018-04-09
@Koteezy

Give your route a name.
( https://laravel.com/docs/5.6/routing#named-routes )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question