1$users = User::where('type', 'instructor')->get();
2 foreach ($users as $user) {
3 $user['ratings'] = $user->ratings()->avg('rate');
4 }
5 return $users;
6
7
8$data = User::with('ratings')
9->join('Rating table','user.id','=','Rating table.user_id')
10->select('user.*',DB::raw('avg(rating_for_user)'))
11->get();