I have 3 tables
And 3 Models
Relationships
Now I want to fetch the products who's user have rating more than 2.
How to write a query?
You can use the whereHas()
method. For example
Suppose your ratings
table has a field rating
that stores the rating value, and that the relationships are named
users
ratings
Then you can attempt
$products = Product::whereHas('users.ratings', function($rating){
$rating->where('rating','>',2);
})->get();