<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\CartItem;
use App\Models\User; 

class CartController extends Controller
{
public function index()
{
    $users = User::with([
            'cartItems.product'
        ])
        ->whereHas('cartItems')
        ->withMax('cartItems', 'created_at')
        ->orderByDesc('cart_items_max_created_at')
        ->get();

    return view('admin.cart_items', compact('users'));
}
}
