php - I found Error in query when i join with another table -
when join 1 table got error. put keyword not working give me error field not found how can solve error
code:
product::leftjoin('reviews','products.id','=','reviews.productid') ->select(array('products.*', db::raw('avg(rating) ratings_average') )) ->where(function($query) use ($categoriesid,$brands,$pricearray,$ratingarray) { $query->wherein('categoryid',$categoriesid); if(count($brands) > 0) { $query->wherein('brandid',$brands); } $query->wherebetween('productsellingprice',$pricearray); if(count($ratingarray) > 0) { $query->wherebetween('ratings_average',$ratingarray); } }) ->groupby('products.id') ->get();
error:
sqlstate[42s22]: column not found: 1054 unknown column 'ratings_average' in 'where clause' (sql: select `products`.*, avg(rating) ratings_average `products` left join `reviews` on `products`.`id` = `reviews`.`productid` (`categoryid` in (9, 11, 31) , `productsellingprice` between 50 , 5000 , `ratings_average` between 1 , 2) group `products`.`id`)
instead of rating array can find out $minrating
, maxrating
. these 2 value can run query this:
$query->wherebetween('rating',[$minrating,$maxrtaing]);
Comments
Post a Comment