2

I want to redirect the user for particular page after successful login.

I don't want the user to navigate to the last viewed page after login.

I have tried following url but its show me error.

Error:

$credentials are required.

Laravel redirect back to original destination after login

Community
  • 1
  • 1
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50

3 Answers3

2

I have changed redirect page using following code after login

Previous

return Redirect::intended('home');

Change to

return Redirect::to('home');
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
1

Add auth filter to your route and add logic to redirect user if login is success or failure.

Your route will look something like:

Route::group(array('domain'=>'a.b.com', 'before'=>'auth'), function() {

and your filter will be like:

Route::filter('auth', function()
{
    if (Auth::user()->guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('account/login');
        }
    }
});

Have a look here for adding route and filter, and here to get basic information regarding filter. These 2 tutorials will also help: Link 1 & Link 2

In your AccountController, try to add something inside validate function:

if (Session::has('url.intended')) {
 $url = Session::get('url.intended');
 Session::forget('url.intended');   // unset referring url from session 
 return Redirect::to($url); // redirect to referring url
}
else {
    return Redirect::to('/');   // redirect to home page
}
Gaurav Dave
  • 6,838
  • 9
  • 25
  • 39
-2

Customize redirect location by defining a redirectPath property on the Auth/AuthController:

protected $redirectPath = '/dashboard';
Kumar Sambhav Pandey
  • 1,713
  • 4
  • 22
  • 33
  • that not works, after login laravel try to go to last page, i means if you refresh your last page on sistem(loged on sistem) and your session is out. the laravel send you to login and after login its send you to your last page, no to $redirectpath. – Rubén Ruíz Jan 16 '18 at 16:27