I have 2 Tables Products and Reviews
- Products hasMany reviews
- Reviews belongsTo Product
I want to get only those product which have avg('ratings') is equal to 5
from controller, I get products = Product::with('category')->with('reviews')->get();
now want show in blade in one part of Top Rated Products
$product->reviews()->avg('ratings')
I used this to get average ratings for a single Product.
Now I want to get a collection of products which has average rating = 5. I tried this line
$products->reviews()->avg('ratings')->where('ratings',5)->take(3)
but this not worked. Can anyone please help me with my problems?