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
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);
}
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.
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);
}
}