vendredi 17 novembre 2017

Laravel 5.5 display list of product order by count on relation

I'm using Laravel 5.5 and I want to display the list of product that order by the most frequently sold items, so i made the relation to shipping_detail table but I got an error. here's the code :

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();

The error :

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

do I have to put all the column of product table in group by or there is another way to do this more simple ??



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AQ46li
via IFTTT

Aucun commentaire:

Enregistrer un commentaire