Php laravel auth()是否正确->;尝试()写入任何会话
我几个月前才学会拉威尔。我想知道一个小问题。 我正在使用auth()->trunt()成功地进行身份验证。Laravel是否自动添加任何session()变量?如果不是,我是否需要自己添加会话变量,或者需要设置某个位置。 ,非常感谢! 这是我的控制器的一部分Php laravel auth()是否正确->;尝试()写入任何会话,php,laravel,authentication,Php,Laravel,Authentication,我几个月前才学会拉威尔。我想知道一个小问题。 我正在使用auth()->trunt()成功地进行身份验证。Laravel是否自动添加任何session()变量?如果不是,我是否需要自己添加会话变量,或者需要设置某个位置。 ,非常感谢! 这是我的控制器的一部分 if (!$check = auth()->attempt([ 'member_username' => request()->$input('username'), 'password'
if (!$check = auth()->attempt([
'member_username' => request()->$input('username'),
'password' => request()->$input('pwd'),
'login_enable' => 1
])){
//processing login successfully
}
下面是web.php的一部分
Route::group(['middleware' => 'auth'], function(){
// Login successfully route
});
下面是auth.php的一部分
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'account',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'account' => [
'driver' => 'eloquent',
'model' => App\Entity\AccountMain ::class,
],
],
当您的guard身份验证是
会话
时,它使用照明\Auth\SessionGuard
类。您可以在这里看到它的尝试
方法:
/**
*尝试使用给定凭据对用户进行身份验证。
*
*@param数组$credentials
*@param bool$还记得吗
*@returnbool
*/
公共函数尝试(数组$credentials=[],$membere=false)
{
$this->fireAttemptEvent($credentials,$memory);
$this->lastAttempted=$user=$this->provider->retrieveByCredentials($credentials);
//如果返回了UserInterface的实现,我们将询问提供者
//根据给定凭据验证用户,以及用户是否处于
//事实有效我们将用户登录到应用程序并返回true。
如果($this->hasValidCredentials($user,$credentials)){
$this->login($user,$memory);
返回true;
}
//如果身份验证尝试失败,我们将触发一个事件,以便用户
//可能会被通知任何可疑的尝试访问他们的帐户从
//无法识别的用户。开发人员可以根据需要侦听此事件。
$this->fireFailedEvent($user,$credentials);
返回false;
}
您可以看到它从这个保护调用login
方法
/**
*将用户登录到应用程序。
*
*@param\Lightning\Contracts\Auth\Authenticatable$user
*@param bool$还记得吗
*@返回无效
*/
公共函数登录(AuthenticatableContract$user,$memory=false)
{
$this->updateSession($user->getAuthIdentifier());
//如果应用程序永久“记住”用户,我们将
//将包含用户加密副本的永久cookie排入队列
//标识符。我们稍后将对此进行解密以检索用户。
如果($记住){
$this->ensureRememberTokenIsSet($user);
$this->queueRecallerCookie($user);
}
//如果我们设置了一个事件调度器实例,我们将触发一个事件,以便
//任何侦听器都将钩住身份验证事件并运行操作
//基于从guard实例触发的登录和注销事件。
$this->fireLoginEvent($user,$memory);
$this->setUser($user);
}
updateSession
调用就是您的答案。当您的guard身份验证是会话时,它使用Lightning\Auth\SessionGuard
类。您可以在这里看到它的尝试
方法:
/**
*尝试使用给定凭据对用户进行身份验证。
*
*@param数组$credentials
*@param bool$还记得吗
*@returnbool
*/
公共函数尝试(数组$credentials=[],$membere=false)
{
$this->fireAttemptEvent($credentials,$memory);
$this->lastAttempted=$user=$this->provider->retrieveByCredentials($credentials);
//如果返回了UserInterface的实现,我们将询问提供者
//根据给定凭据验证用户,以及用户是否处于
//事实有效我们将用户登录到应用程序并返回true。
如果($this->hasValidCredentials($user,$credentials)){
$this->login($user,$memory);
返回true;
}
//如果身份验证尝试失败,我们将触发一个事件,以便用户
//可能会被通知任何可疑的尝试访问他们的帐户从
//无法识别的用户。开发人员可以根据需要侦听此事件。
$this->fireFailedEvent($user,$credentials);
返回false;
}
您可以看到它从这个保护调用login
方法
/**
*将用户登录到应用程序。
*
*@param\Lightning\Contracts\Auth\Authenticatable$user
*@param bool$还记得吗
*@返回无效
*/
公共函数登录(AuthenticatableContract$user,$memory=false)
{
$this->updateSession($user->getAuthIdentifier());
//如果应用程序永久“记住”用户,我们将
//将包含用户加密副本的永久cookie排入队列
//标识符。我们稍后将对此进行解密以检索用户。
如果($记住){
$this->ensureRememberTokenIsSet($user);
$this->queueRecallerCookie($user);
}
//如果我们设置了一个事件调度器实例,我们将触发一个事件,以便
//任何侦听器都将钩住身份验证事件并运行操作
//基于从guard实例触发的登录和注销事件。
$this->fireLoginEvent($user,$memory);
$this->setUser($user);
}
updateSession
电话就是你的答案。我知道了!!`函数updateSession($id){$this->session->put($this->getName(),$id);$this->session->migrate(true);}`它将MySQL表的键放到会话中。这真的很有帮助!会话有一个奇怪的密钥字段名,如login\u web\u 59ba36addc2b2f9401580f014c7f58ea4e30989,它确保了会话名的唯一性,无论绑定的实体是什么!!`函数updateSession($id){$this->session->put($this->getName(),$id);$this->session->migrate(true);}`它将MySQL表的键放到会话中。这真的很有帮助!会话有一个奇怪的键