0
votes

I am stuck with getting the redirectTo() function override in my LoginController.php as shown in the Laravel docs here.

My controller contains:

/**
 * URI where we redirect to after login
 *
 * @var string
 */
protected $redirectTo = 'player/home';

/**
 * Set route redirect
 *
 * @return mixed
 */
protected function redirectTo()
{
    dd("STOP"); <-- does not trigger

    if (session()->has('game.details')) {
        return route(session()->get('game.details.setup_route'));
    } else {
        return 'player/home';
    }
}

Why would the dd never trigger and the page always redirects to player/home? Thanks

3
Use dd(session()->get('game.details.setup_route')); and see the result! - Hiren Gohel
Hi @Hiren Gohel, no difference. Still redirects to player/home. I tried a simpler version of your suggestion. See my question updated. Ta - TheRealPapa
Have you tried getting rid of the protected $redirectTo line? - ceejayoz
@HirenGohel The dd call should still occur and interrupt everything. - ceejayoz
Yes I just updated it to a simpler dd. Still not stopping - TheRealPapa

3 Answers

1
votes

If you comment $this->middleware("guest") in the constructor of Auth\RegisterController or change the line about guest middleware in the Kernel.php it will be worked.

0
votes

Although I did not get the method override working, I solved it by changing these lines in the login method:

    if ($this->attemptLogin($request)) {
        session()->put('game.details', Game::findByUUIDOrFail($uuid));

        $this->redirectTo = route(session()->get('game.details.setup_route'));

        return $this->sendLoginResponse($request);
    }
0
votes

If you have run php artisan auth

change the RedirectIfAuthenticated Middleware like so

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {

            return redirect('/home');//change the redirect here
        }

        return $next($request);
    }
}