Add all files
This commit is contained in:
36
app/Admin/Widgets/ActiveUsers.php
Normal file
36
app/Admin/Widgets/ActiveUsers.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Widgets;
|
||||
|
||||
use Filament\Widgets\Widget;
|
||||
|
||||
class ActiveUsers extends Widget
|
||||
{
|
||||
protected static string $view = 'admin.widgets.active-users';
|
||||
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected static string $title = 'Active Users';
|
||||
|
||||
public function render(): \Illuminate\View\View
|
||||
{
|
||||
$baseQuery = \App\Models\Session::query()
|
||||
->where('last_activity', '>=', now()->subMinutes(5))
|
||||
->whereNotNull('user_id')
|
||||
->orderBy('last_activity', 'desc')
|
||||
->with('user');
|
||||
|
||||
$sessions = (clone $baseQuery)->limit(5)->get();
|
||||
$onlineCount = (clone $baseQuery)->count();
|
||||
|
||||
return view(static::$view, [
|
||||
'sessions' => $sessions,
|
||||
'onlineCount' => $onlineCount,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()->hasPermission('admin.widgets.active_users');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user