1

laravel 5 redirect to previous page after sign in.

When I am hitting a url manually if its not logged in its redrecting to login page but after login it should redirect to url which entered but in my case its going to home page.

Code:

public function index()
    { 

            // Is the user logged in?
        if (Auth::check()) 
        { 
            return Redirect::route('dashboard');
        }

        // Show the page
        return View('auth.login');
    }


public function getSignin()
    { 

            // Is the user logged in?
        if (Auth::check()) 
        { 
            return Redirect::route('dashboard');
        }

        // Show the page
        return View('auth.login');
    }
user6527
  • 55
  • 1
  • 12
  • Or should i change Middleware ?? – user6527 Dec 01 '16 at 10:03
  • 1
    Possible duplicate of [Laravel redirect back to original destination after login](http://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login) – jannej Dec 01 '16 at 10:08

2 Answers2

1

In LoginController and RegisterController, replace the field $redirectTo with the following:

protected function redirectTo(){
    return url()->previous();
}
Luca C.
  • 11,714
  • 1
  • 86
  • 77
0

you can use redirect()->back() in case if the user is logged in

Bara' ayyash
  • 1,913
  • 1
  • 15
  • 25
  • redirect()->back(); wont work as the previous url will be login page and if its goes to login page as its already logged it it will redirect to home page... – user6527 Dec 01 '16 at 10:16
  • you can find your answer here : [link](http://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login?noredirect=1&lq=1) – Bara' ayyash Dec 01 '16 at 10:27
  • without using middelware can we do this ?? – user6527 Dec 01 '16 at 10:53
  • try to use this replace ` return Redirect::route('dashboard');` with `return Redirect::intended('dashboard');` ` – Bara' ayyash Dec 01 '16 at 10:58