1

I want to redirect the user after login to '/details'..but it redirect me to '/home'

LoginController.php

public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...
            return redirect()->intended('/details');
        }
        return redirect('/details');

    }

RouterServiceProvider.php

public const HOME = '/details';

I've tried this.but still can't do it

Laravel redirect back after login

Eman Emad
  • 77
  • 1
  • 4
  • 13

4 Answers4

6

By default In your LoginController just replace

protected $redirectTo = '/home';

TO

protected $redirectTo = '/details';

But if you use own authenticate so you use like this

public function authenticate(Request $request)
{
    $credentials = $request->only('email', 'password');

    if (Auth::attempt($credentials)) {
        // Authentication passed...
        return redirect($this->redirectPath());
        //return redirect()->intended('/details');
    }
    return redirect($this->redirectPath());

}
A.A Noman
  • 5,244
  • 9
  • 24
  • 46
  • @HilaryOkoro It's working fine for me and others three who use this follow this instruction. So please check your code and review. Check this link also https://stackoverflow.com/questions/61754023/laravel-redirect-to-login-page-after-successful-verification?noredirect=1#comment109234612_61754023 – A.A Noman Aug 13 '20 at 06:26
3

In your Auth\LoginController.php, you can override the function used after login :

/**
 * The user has been authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  mixed  $user
 * @return mixed
 */
protected function authenticated(Request $request, $user)
{
    return redirect()->route('route.name');
}
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84
1

Laravel 7

Can use authenticated function in these ways:

1. Change Original Function

original authenticated function is stored in vendor/laravel/ui/auth-backend/AuthenticatesUsers.php, change it like below:

protected function authenticated(Request $request, $user)
{
    if ($user->is_superuser) {
        return redirect('/admin');
    }
    return redirect('/');
}

2. Overwrite

in LogniController stored in app/Http/Controllers/LoginController.php paste top function.

Tip: is_superuser is a boolean field in users table and shows that a user is admin (superuser) or not.

Arash Younesi
  • 1,671
  • 1
  • 14
  • 23
0

Go to RouteServiceProvider.php file and change the route from '/home'to what you want.