Classificação AVG entre no Laravel 8

$users = User::where('type', 'instructor')->get();
  foreach ($users as $user) {
      $user['ratings'] = $user->ratings()->avg('rate');
  }
  return $users;


$data = User::with('ratings')
->join('Rating table','user.id','=','Rating table.user_id')
->select('user.*',DB::raw('avg(rating_for_user)'))
->get();
Tyagi420