2017-11-18 17 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 

は私がすることで、グループ内の製品のテーブルのすべての列を入れなければならないのか、これ以上簡単な操作を行うための別の方法があります?

+1

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

+0

...解決のおかげ@AndriyLozynskiy –

答えて

1

は、それがfalseに変更された場合は、あなたのMySQLが厳しいconfig/database.phpファイル

に施行持っていません。すなわち

'strict' => false, 
関連する問題