User::count(), 'total_products' => Product::count(), 'approved_products' => Product::approved()->count(), 'pending_products' => Product::pending()->count(), 'rejected_products' => Product::rejected()->count(), 'total_categories' => Category::count(), 'total_comments' => Comment::count(), 'total_upvotes' => Upvote::count(), ]; // User Growth (last 7 days) $userGrowth = User::where('created_at', '>=', now()->subDays(7)) ->selectRaw('DATE(created_at) as date, COUNT(*) as count') ->groupBy('date') ->orderBy('date') ->get(); // Product Growth (last 7 days) $productGrowth = Product::where('created_at', '>=', now()->subDays(7)) ->selectRaw('DATE(created_at) as date, COUNT(*) as count') ->groupBy('date') ->orderBy('date') ->get(); // Top Categories (by product count) $topCategories = Category::withCount('products') ->orderBy('products_count', 'desc') ->limit(5) ->get(); // Recent Users $recentUsers = User::with('roles') ->latest() ->limit(5) ->get(); // Recent Products $recentProducts = Product::with(['user', 'category']) ->latest() ->limit(5) ->get(); // Most Upvoted Products $topProducts = Product::approved() ->withCount('upvotes') ->orderBy('upvotes_count', 'desc') ->limit(5) ->get(); return view('admin.dashboard', compact( 'stats', 'userGrowth', 'productGrowth', 'topCategories', 'recentUsers', 'recentProducts', 'topProducts' )); } }