$total = $query->count(\DB::raw("distinct(product_skus.id)")); $query = $query->orderBy(‘product_skus.id‘, ‘desc‘); $skuList = $query->distinct(‘product_skus.id‘)->paginate($pageSize, [‘product_skus.id‘]); $skuListArr = $query->distinct(‘product_skus.id‘)->get()->toArray();