Laravel 5: After login the user is was redirected

2019-07-13 10:42发布

问题:

I have created my own root page (/) as well as my register page (/cadastrar). My next step was to allow the user to login and update their information. For that I just used laravel's login page (/auth/login). It works fine and when I login I get redirected to /home. At this point my problem arises: I can not go to any other page (/) (/cadastrar). I always get redirected back to /home.

I did not change any configuration regarding login or redirections so what could be wrong and how to fix it?

EDIT: At my (/) I have a Sign in link. When I click, I go to (/auth/login). I put my email and password, press login and it redirects me to (/home) saying that I'm logged in. Now I want to go to (/) or any other page, but it always redirect me to (/home). Thats my problem. My plan was to let the users update their information only if they are logged in, but now I can't go anywhere.

回答1:

In app/Http/Middleware/RedirectIfAuthenticated.php on line 38 change:

return new RedirectResponse(url('/home'));

to

return new RedirectResponse(url('/'));


回答2:

I noticed that when I went into my WelcomeController and commented out the line in the __construct function that assigned this page only to guests the redirection problem was gone:

//$this->middleware('guest');