getViewsForLast10Days(Tour::class, 'tour_views'); $flightViews = $this->getViewsForLast10Days(Flight::class, 'flight_views'); $logs = ActivityLog::with('admin') ->latest() ->take(5) ->get(); return view('admin.dashboard', compact( 'adminsCount', 'usersCount', 'toursCount', 'flightsCount', 'tourViews', 'flightViews', 'logs' )); } private function getViewsForLast10Days(string $model, string $cachePrefix) { $ids = $model::pluck('id'); return collect(range(9, 0))->map(function ($i) use ($ids, $cachePrefix) { $date = now()->subDays($i)->format('Y-m-d'); $total = $ids->sum(function ($id) use ($cachePrefix, $date) { return Cache::get("{$cachePrefix}:{$id}:{$date}", 0); }); return [ 'date' => verta($date)->format('m/d'), 'total' => (int) $total, ]; })->values(); } }