我试着在默认的Auth脚手架中寻找Laravel破坏会话的地方,但我找不到。但是,我可以找到清除的地方,。在logout()中默认的AuthenticateUsers.php函数:
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return $this->loggedOut($request) ?: redirect('/');
}$this->guard()->logout();指向StatefulGuard.php:
/**
* Log the user out of the application.
*
* @return void
*/
public function logout();$request->session()->invalidate();指向Store.php中的invalidate()函数,后者也指向Store.php中的flush()。然而,这个函数只清除会话,但它不会破坏它:
/**
* Remove all of the items from the session.
*
* @return void
*/
public function flush()
{
$this->attributes = [];
}因此,我在这里的问题是:甚至在默认的Auth脚手架中销毁会话吗?,如果是这样的话:它在哪里做这个呢?我绝对找不到它,我已经找了好几个小时了。
附注:不要将其标记为重复,因为使用Session::刷新()并不能回答我的问题。
发布于 2019-07-05 08:01:01
好的,所以我刚找到它。原来我一直都是瞎子。
invalidate()函数在Store.php 中返回 $this->migrate(true)。此函数使用默认的PHP SessionHandlerInterface来销毁会话:
/**
* Generate a new session ID for the session.
*
* @param bool $destroy
* @return bool
*/
public function migrate($destroy = false)
{
if ($destroy) {
$this->handler->destroy($this->getId());
}
$this->setExists(false);
$this->setId($this->generateSessionId());
return true;
}发布于 2019-07-05 08:13:14
您可以使用会话的破坏()方法完全销毁它,尝试使用,
$request->session()->destroy();将其放入您的注销方法或该方法的调用之后,以便在您从系统中注销后,它将被销毁。
https://stackoverflow.com/questions/56898866
复制相似问题