After login, I am redirected to the root of the application (http://example.com).
I know this happens because the intended URL was the root of the application. I am trying to change that behavior. I want the user to select the page he/she wants to see upon login, regardless of his/her intended URL and redirect the user to that page upon login. I set the $redirectTo variable but it only works when the first page I visit is the login route and not the base URL. Is there any solution to this?
protected $redirectTo = '/your-page'; in your LogInController.
What your asking is something that you would have to write code for. Out of the box with auth, Laravel will redirect to the login page if not authenticated when the user selects any page. Use that basis as an idea of how to do it and then redirect to the intended page.
Funny enough, Laravel redirects to my intended URL. I see many users complaining about redirect()->intended() but Laravel does this out of the box. I am trying to prevent that feature
You only need to return a redirect to wherever you want the user to go. If you want the user to choose a redirect, you will have to implement some type of intercepter to redirect to the route after login. Use a login form value to add to the redirect url to accomplish allowing the user to choose.
/**
* Where to redirect users after authentication.
*
* @var string
*/
public static $afterLoginRedirectTo = '/home';
/**
* Where to redirect users after authentication.
*
* @return string
*/
public static function afterLoginRedirect()
{
return static::$afterLoginRedirectTo;
}
/**
* Set the path to redirect to after authentication.
*
* @return void
*/
public static function afterLoginRedirectTo($path)
{
static::$afterLoginRedirectTo = $path;
}