cs1h cs1h - 21 days ago 8
PHP Question

Laravel 5 - After login redirect back to previous page

I have a page with a some content on it and a comments section. Comments can only be left by users who are signed in so I have added a login form to the page for users to sign in with (this only shows if they are not already logged in).

The problem I have is that when the user signs in they get redirected back to the home page and not the page they were previously on.

I have not changed the login method from the out of the box set-up.

Can anyone suggest a simple way to set the redirect url. My thoughts are that it would be good to be able to set it in the form.

Answer

In

app/Http/Controllers/Auth/AuthController.php

add this line and change '/' to your location.

protected $redirectPath = '/';