vendredi 23 juin 2017

Laravel multiple where queries not working

I have the following query that seems to go wrong on the second where (search_price < rrp_price)

$query = Product::where('product_name', '!=', 'product_name');

$likes = DB::table('likes')->selectRaw('product_id, COUNT(*) as count')
                  ->groupBy('product_id')
                  ->orderBy('count', 'desc')
                  ->get();
foreach($likes as $like){
   if($like == $likes[0]){
      $query->where('aw_product_id', $like->product_id');
   }
   else{
      $query->orWhere('aw_product_id', $like->product_id');
   }
}
$query->whereRaw('search_price != rrp_price');
$products = $query->get();

So, if i take out the 'search_price < rrp_price' where i get all products filtered by those product ids with no price filtering, but when i leave the 'search_price < rrp_price' filter in, nothing seems to happen (search_price and rrp_price are always the same).

Am i doing anything obvoiously wrong with my where statements?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire