我已經這樣做了:https ://shouts.dev/articles/how-to-get-online-users-in-laravel ,它作業正常。
但我想擺脫注銷的用戶。否則串列會太大。這是我的注銷線路:
<li>
<a ui-sref="auth.logout">
<img src="/img/loader-blue.gif" class="img-responsive pull-left margin-top-2 margin-right-4 hide" ng-class="{'show': loadingState == 'auth.logout'}" width="17" height="17">
<i hljs-string">" ng-hljs-string">'hide': loadingState == 'auth.logout'}"></i> {{_('Log out')}}
</a>
</li>
所以,在這里的某個地方,當用戶注銷時,我想在我的用戶表中“NULL”列“last_seen”。
如何?
uj5u.com熱心網友回復:
你可以試試這個:
$id = Auth::id();
$user = User::find($id);
$user->update([
'column_name' => null
]);
Auth::logout(); // logout the user
uj5u.com熱心網友回復:
在控制器的注銷部分,只需在注銷用戶之前將該列更新為 null。
User::where('id', Auth::user()->id)->update(['last_seen' => null]);
但我認為這并不能解決您的問題,因為用戶通常只是關閉瀏覽器而不注銷。
如果你想只顯示在線的人,根據代碼人們在最后 2 分鐘內積極瀏覽你的網站(參見中間件),只需在 UserController 中過濾查詢。
User::where('last_seen', '<=', now()->subMinutes(2))
->orderBy('last_seen', 'DESC')
->paginate(5);
uj5u.com熱心網友回復:
因此,在 Roberto Braga 的幫助下,我在 UserController 中使用了這段代碼:
$users = User::where('last_seen', '>=', now()->subMinutes(2))
->orderBy('last_seen', 'DESC')
->paginate(5);
用戶在不活動時會在兩分鐘后從串列中消失,并在活動增加時重新出現。偉大的!
uj5u.com熱心網友回復:
添加用戶模型 $fillable = ['last_seen',...];
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/520425.html
下一篇:將影像(從url)轉換為檔案
