Laravel 【Laravel / orderBy】 リレーション先の数でorderByする えびさん withCount([リレーション先名])を追加orderByの第一引数で[リレーション先名] _countを指定する Userテーブルに紐づくPostの数で並べ替えしたい場合 User::withCount('posts')->orderBy('posts_count', 'desc')->get(); ツイート シェア はてブ 送る Pocket