请我尝试在原始sql中运行看起来像这样的查询

SELECT `qnty`, COUNT(*) FROM cartlist GROUP BY `pro_id`,`cart_id`,`price`

在laravel。

我已经试过了
$count = DB::table('cartlist')
                 ->select(DB::raw('count(*) as qnty'))
                 ->where('pro_id', '$tt->pro_id')
                 ->where('cart_id', '$cart_id')
                 ->groupBy('pro_id','price')
                 ->get();

但是它给出了以下错误

Illuminate \ Support \ Collection类的对象无法转换为int

最佳答案

$count = DB::table('cartlist') ->select(DB::raw('count(*) as qnty'))
                               ->where('pro_id', '$tt->pro_id')
                               ->where('cart_id', '$cart_id')
                               ->groupBy('pro_id','price','cart_id') ->get();

10-07 19:53
查看更多