Did you ever need to order based on a related model's average or count?
It's easy with Eloquent!
public function bestBooks()
{
Book::query()
->withAvg('ratings as average_rating', 'rating')
->orderByDesc('average_rating');
}
Did you ever need to order based on a related model's average or count?
It's easy with Eloquent!
public function bestBooks()
{
Book::query()
->withAvg('ratings as average_rating', 'rating')
->orderByDesc('average_rating');
}