[英]How to store data in an authentication session
我正在嘗試在會話中存儲一些特定於身份驗證的數據,一旦用戶注銷,該數據將被銷毀。
我已經試過了:
if ($didLogin) {
// Save the client id in session
$request->session()->put('client_id', $input['client_id']);
return redirect()->intended('/');
}
這有效,但是一旦用戶注銷或自動注銷,就不會刪除數據。
我已經閱讀了文檔,但似乎尚不清楚,我只需要在登錄過程中提供一些其他數據即可。
注銷時刷新用戶會話
將此方法放在您的控制器(例如UserController)中,並在用戶單擊注銷按鈕(例如,用戶/注銷)時調用此方法
這樣,在用戶注銷時,所有會話數據都被清除了。
//User Logout
public function getLogout()
{
Session::flush();
$this->auth->logout();
return redirect('/');
}
您具有身份驗證系統,因此當用戶要注銷時,請單擊以下方法,在下面,我們有Session::flush();
,這將破壞會話數據。
public function logout()
{
Auth::logout();
Session::flush();
return redirect('/login');
}
現在,您有一個空的client_id
。 您可以像這樣檢查
if ($request->session()->has('client_id')) {
return 'Data exists';
}
return 'Data does not exists';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.