Laravelでは、WithCountメソッドでリレーションの数を取得できます。
https://readouble.com/laravel/6.x/ja/eloquent-relationships.html#counting-related-models
// RecipeにFavoriteのHasManyリレーションがある場合
Recipe::withCount('favorites')
->orderBy('favorites_count', 'desc')
->limit(3)
->get();
内部ではサブクエリが発行されています。
"select `recipes`.*, (select count(*) from `recipe_favorites` where `recipes`.`id` = `recipe_favorites`.`recipe_id`) as `favorites_count` from `recipes` order by `favorites_count` desc limit 3"