I have these models, Venue, Review, User.
a User can score several venues.
A venue
has many reviews
A review
belongs to a venue
and user
on my Venue model I have a method which calculates score of a venue:
public function score()
{
$reviewCount = $this->reviews()->count();
$qualitySum = $this->reviews()->sum('quality') * 2;
$decorSum = $this->reviews()->sum('decor');
$venueAverage = ($qualitySum + $decorSum) / ($reviewCount * 30);
$minReview = 5;
//based on weighted average and Barnsley average
$average = ($reviewCount * Review::R()) / ($reviewCount + $minReview) + ($minReview * $venueAverage) / ($reviewCount + $minReview);
$average = round($average, 1);
return $average;
}
Here is the question: How can I retrieve those venues which score is >3
And how can I order results based on score