我有多语言应用程序,因此当用户登录或注册时,需要将他们重定向到特定语言的家。在我的情况下,en/home
或pt/home
。
我已经尝试覆盖中的$redirectTo
属性Login/Register Controllers
,但是它不起作用。
protected $redirectTo = '/home';
protected function redirectTo()
{
return app()->getLocale().'/home';
}
还尝试使用该authenticated
方法:
protected function authenticated(Request $request, $user)
{
return redirect(app()->getLocale() .'/home');
}
为什么这种方法不起作用?我在SO中查看了与此有关的大多数问题,但到目前为止,没有任何答案有效。
这实际上是RedirectIfAuthenticated.php
文件上的问题。我必须将handle函数更改为:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect()->route('home', app()->getLocale());
}
return $next($request);
}
当用户关闭浏览器但未注销,然后尝试在很短的时间内(在登录令牌到期之前)再次访问该页面时,将调用函数而不是中的redirectTo()
方法LoginController
。因此,问题仅在此特定情况下发生。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句