xxxxxxxxxx
$rate_laptops = Product::select('products.*')
->selectSub(
'SELECT AVG(rating) FROM ratings WHERE product_id = products.id',
'average_rating'
)
->orderBy('average_rating', 'desc')
->take(4)
->get();
select AVG(rating) and assume that average_rating
// this is to filter products that have most average rating with ratings pivot
// table
// in ratings, product_id, user_id, rating