laravel order by first hasMany code example
Example: laravel orderby with relation
$users = User::with(['student' => function ($q) {
$q->orderBy('id', 'desc');
}]);
$users = User::with(['student' => function ($q) {
$q->orderBy('id', 'desc');
}]);