且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 5.2,auth :: check登录后返回true,但重定向后返回false

更新时间:2023-12-03 23:05:16

所有需要会话(Auth使用)的路由都必须应用'web'中间件.

ALL routes that require sessions (which Auth uses) must have the 'web' middleware applied.

也:

您的Auth::check()是在仅在Auth::guest()为true的情况下运行的代码块中完成的. Auth::guest()Auth::check()的倒数.

Your Auth::check() is being done in a code block that only runs if Auth::guest() is true. Auth::guest() is the inverse of Auth::check().

因此,您在中间件中说:如果当前用户是访客(未认证),请检查他们是否是已认证用户,这时始终为假.

So you are saying in your middleware: If the current user is a guest (not authenticated), check if they are an authenticated user, which will always be false at this point.

更新:

根据您的评论:不要将经过身份验证的中间件添加到"web"组.否则,您将永远无法打通网络"路线,除非您在进行此更改之前已通过身份验证.如果这样做,您甚至将无法登录.

Based on your comments: Do not add the authenticate middleware to the 'web' group. You will never be able to hit a 'web' route if you do this unless you were authenticated before you made this change. You are removing the ability to even be able to login if you do this.