$users = UserDetails::select('user_details.user_id','user_details.user_nickname',
'user_media.media_url','sport_group_details.sport_group_name')
->join('users', function($join)
{
$join->on('user_details.user_id', '=', 'users.id');
})->join('user_media',function($join){
$join->on('user_details.user_id', '=', 'user_media.user_id');
})->join('user_to_sport_group_values',function($join){
$join->on('user_media.user_id', '=', 'user_to_sport_group_values.user_id');
})->join('sport_group_details',function($join){
$join->on('user_to_sport_group_values.sport_group_id', '=', 'sport_group_details.sport_group_id');
})
->selectRaw('( 6371 * acos( cos( radians(?) ) *
cos( radians( user_lat ) )
* cos( radians( user_lng ) - radians(?)
) + sin( radians(?) ) *
sin( radians(user_lat ) ) )
) AS distance', [$lattitude, $longitude, $lattitude])
->havingRaw("distance <= ?", [$max_distance])
->orderBy('distance')
->orderBy('user_details.user_nickname')->where('users.id','!=',$user_id)
->where('media_type','=','profile')
->where('sport_group_details.language_code','=', $country_code)
->get();
用户可以有多个Sport_group_name,所以我想为单个用户获得所有Sport_group_name以及其他数据,但是我得到用户重复多次,如何过滤重复的用户,我们将不胜感激,谢谢。