Did you ever need to order based on a related model's average or count?
It's easy with Eloquent!
1public function bestBooks()2{3 Book::query()4 ->withAvg('ratings as average_rating', 'rating')5 ->orderByDesc('average_rating');6}
Tip given by @mmartin_joo