请问我正在尝试在原始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
答案 0 :(得分:1)
$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();