我使用 Laravel 中提供的基本 HTTP 身份验证来登录我的网站。然而,当我打电话时Auth::Check()
我总是得到false即使我已登录,也会得到响应。
Does Auth::Check()
不适用于基本身份验证模型,如果不能,是否有任何方法可以检查基本身份验证以查看用户是否已登录?
这是我的用户类别:
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
}
这是我设置要使用的身份验证过滤器的代码段
$this->middleware('auth.basic', ['only' => ['create', 'store', 'edit', 'update', 'destroy']]);
这是我的Auth::Check()
调用(始终打印 0):
public function show($id)
{
echo \Auth::check() ? '1' : '0';
die();
#.......
}
My routes: