In the documentation mentioned using the redirectTo method in the Authentication controller can do custom logic redirection. However, that doesn't work.
This is the workaround and should be fix on the next version.
public function redirectPath()
{
if ( method_exists($this, 'redirectTo') ) {
return $this->redirectTo();
} else {
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
}
I don't see where's the problem, the original implementation works fine:
public function redirectPath()
{
if (method_exists($this, 'redirectTo')) {
return $this->redirectTo();
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
If a method exists it'll use it other wise the property will be used.
I'm having this same issue:
In your LoginController, create a method name redirectTo() and return the path string.
Login your application. It will always point to /home
It seems to be triggering the RedirectIfAuthenticated middleware:
public function handle($request, Closure $next, $guard = null)
{
if(Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
The problem is with documentation, because show this:
If the redirect path needs custom generation logic you may define a redirectTo method instead of a redirectTo property:
protected function redirectTo()
{
//
}
redirectTo method has higher priority than redirectTo attribute.
But you need define redirectPath() method actually.
Have same issue with 5.4.13, and the problem solved by @RichieMcMullen solution above.
just use return "/home"; for example do not use redirectTo('home');
If you need more robust customization of the response returned when a user is authenticated, Laravel provides an empty authenticated(Request $request, $user) method that may be overwritten if desired:
So put this method in LoginController.php
protected function authenticated(Request $request, $user)
{
return redirect()->route('displayNew');
}
Most helpful comment
I'm having this same issue:
In your LoginController, create a method name redirectTo() and return the path string.
Login your application. It will always point to /home
It seems to be triggering the RedirectIfAuthenticated middleware: