当用户未登录时,我在将内置 Laravel Auth 重定向到正确路径时遇到问题。
从文档看来,我可以将以下内容添加到 AuthController.php
// redirect paths
protected $redirectPath = '/profile';
protected $loginPath = '/home';
protected $redirectAfterLogout = '/home';
添加它应该允许我控制在各种情况下重定向用户的位置,但似乎没有任何效果。
挖掘代码我可以看到 auth/login 路由是在 handle 函数的 middleware/authenticate.php 中设置的,如下所示:
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
return $next($request);
}
如果我在这里更改路径,它会起作用,但这肯定不是实现它的最佳方法。
我正在使用 Laravel 5.1.7 并尝试过 php artisan route:clear
任何想法/建议都会很棒。