为什么 Laravel AuthGuard 接口没有 attempt() 方法?
Why Laravel AuthGuard interface doesn't have the attempt() method?
在 Laravel 文档中声明使用 attempt() 方法进行身份验证,但它不在 Auth Guard 界面中,因此您的自定义防护失败。
这是为什么?
您可以使用 Auth
外观来验证用户。
using Illuminate\Support\Facades\Auth;
// $credentials should have 'email' and 'password' keys
if (Auth::attempt($credentials)) {
// success
}
只有 SessionGuard
有这个方法,因为它实现了 StatefulGuard
接口。其他守卫没有这个方法,所以它不能成为 Guard
接口的一部分,因为并非所有守卫都是有状态的。
在 Laravel 文档中声明使用 attempt() 方法进行身份验证,但它不在 Auth Guard 界面中,因此您的自定义防护失败。
这是为什么?
您可以使用 Auth
外观来验证用户。
using Illuminate\Support\Facades\Auth;
// $credentials should have 'email' and 'password' keys
if (Auth::attempt($credentials)) {
// success
}
只有 SessionGuard
有这个方法,因为它实现了 StatefulGuard
接口。其他守卫没有这个方法,所以它不能成为 Guard
接口的一部分,因为并非所有守卫都是有状态的。