拜托,我正在尝试在原始 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();
关于Laravel 5.3 “group by count” 查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40127834/