feat: add usage statistics section to activity log page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,4 +18,38 @@ class ActivityLogController extends Controller
|
||||
]);
|
||||
return response()->json($logs);
|
||||
}
|
||||
|
||||
public function stats()
|
||||
{
|
||||
$today = now()->startOfDay();
|
||||
$week = now()->startOfWeek();
|
||||
$month = now()->startOfMonth();
|
||||
|
||||
$byType = ActivityLog::selectRaw('action, COUNT(*) as total')
|
||||
->groupBy('action')
|
||||
->pluck('total', 'action');
|
||||
|
||||
$topUsers = ActivityLog::selectRaw('user_name, COUNT(*) as total')
|
||||
->whereNotNull('user_name')
|
||||
->groupBy('user_name')
|
||||
->orderByDesc('total')
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
$daily = ActivityLog::selectRaw('DATE(created_at) as day, COUNT(*) as total')
|
||||
->where('created_at', '>=', now()->subDays(13)->startOfDay())
|
||||
->groupBy('day')
|
||||
->orderBy('day')
|
||||
->pluck('total', 'day');
|
||||
|
||||
return response()->json([
|
||||
'logins_today' => ActivityLog::where('action', 'login')->where('created_at', '>=', $today)->count(),
|
||||
'logins_week' => ActivityLog::where('action', 'login')->where('created_at', '>=', $week)->count(),
|
||||
'logins_month' => ActivityLog::where('action', 'login')->where('created_at', '>=', $month)->count(),
|
||||
'actions_today' => ActivityLog::where('created_at', '>=', $today)->count(),
|
||||
'by_type' => $byType,
|
||||
'top_users' => $topUsers,
|
||||
'daily' => $daily,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user