我有一個名爲active_user的列以顯示用戶何時在線(1)。當我登錄用戶時,我將active_user列設置爲1,但是當我登錄用戶並檢查active_user時,它仍然顯示在線(1)。我想要的是,當我單擊註銷按鈕時,aactive_user列將更改爲脫機(0)並將其更新到數據庫。我的登錄信息如下。如何在退出時更改laravel中的列的值
public function postSignIn(Request $request) {
$this->validate($request, [
'email' => 'required',
'password' => 'required'
]);
if(Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
$user=User::whereRaw('email=?',[Input::get('email')])->first();
//this is where i set the active_user to 1
$user->active_user=1;
$user->save();
if($user!=null){
switch($user->role_id){
case 1:
if($user->status==0){
session()->flash('flash_message_error', ' Your Account has been deactivated. Contact the administrator');
return Redirect::to('admin/login');
}
return redirect()->route("index");
break;
然後下面是註銷功能我註銷功能
public function LogOut($id) {
$user = User::find($id);
$user->active_user=1;
$user->save();
Auth::logout();
return redirect('admin/login');
}
我想改變active_user回到離線(0),但我不斷收到錯誤「缺少參數1爲App \的Http \ Controllers \ AdminController :: LogOut()「
您可以使用登錄/註銷事件..看看這個公認的答案:http://stackoverflow.com/questions/36767556/laravel-auth-count-user-login/36767937#36767937 –
什麼我試圖做的是更新active_user返回到離線(0)當我clcik註銷按鈕 –