relationship laravel with order by code example
Example 1: laravel orderby with relation
$users = User::with(['student' => function ($q) {
$q->orderBy('id', 'desc');
}]);
Example 2: laravel OrderBy on Eloquent whereHas relationship
$counties = County::whereHas('items', function ($query) {
$query->where('approved', 1);
})->orderBy('name')->get();