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');}
Tip given by @mmartin_joo