$entry->save();
}
+
+ /**
+ * Returns combinations of file/user access using many different sessions
+ * @param int $limit
+ * @return \Illuminate\Support\Collection
+ */
+ public static function suspicious($limit = 10): \Illuminate\Support\Collection
+ {
+ return self::query()
+ ->whereNotNull('session_id')
+ ->whereNotNull('user_id')
+ ->where('user_id', '>', '100')
+ ->get()
+ ->groupBy(['user_id', 'file_id'])
+ ->flatten(1)
+ ->mapWithKeys(function($c) {
+ $key = $c->first()->user_id . '.' . $c->first()->file_id;
+ $count = $c->groupBy('session_id')->count();
+
+ return [$key => $count];
+ })
+ ->sortDesc()
+ ->take($limit);
+ }
}