2017-11-18 149 views
0

我使用的是Laravel 5.5,我想显示由最频繁销售的物品订购的产品清单,因此我对shipping_detail表进行了关联,但是我得到了错误。下面的代码:Laravel 5.5根据关系计数显示产品订单清单

Produk::select('product.*', \DB::raw('COUNT(shipping_detail.product_code) as total')) 
     ->leftJoin('shipping_detail', 'shipping_detail.product_code', '=', 'product.product_code') 
     ->whereIn('product.category_id', $cat) 
     ->orWhere('product.category_id', $prod_cat_id) 
     ->groupBy('product.product_code') 
     ->orderBy('total', 'desc') 
     ->limit(7) 
     ->get(); 

错误:

SQLSTATE[42000]: Syntax error or access violation: 1055 'store.product.category_id' isn't in GROUP BY 

我必须把产品表中的所有列在GROUP BY或有另一种方式来做到这一点更简单?

+1

https://stackoverflow.com/questions/41571271/group-by-not-working-laravel –

+0

解决了..谢谢@AndriyLozynskiy –

回答

1

请问你的mysql已经严格执行在config/database.php文件

如果是假的变化。即

'strict' => false,