刚开始用laravel写server, 这里有两张表aws_users, lecture_share_info,
aws_users表里有用户的一些信息, lecture_share_info表记录好友关系(一个用户有多个好友, user_id, friend_id都关联至aws_users里的uid)
现在需要获取lecture_share_info表里某个user对应的所有friends的头像, 并按lecture_share_info的id降序排.
我下面的写法会按照user表的用户id排序而不是lecture_share_info.id 大家知道正确的写法吗?
  public static function getSupportedAvatars($uid)
    {
        $avatars = User::whereIn('uid', function ($query) use ($uid) {
           $query->select('friend_id')->from('lecture_share_info')
               ->where('user_id','=', $uid)->orderBy('lecture_share_info.id', 'Desc');
        })->lists('aws_users.avatar_file')->toArray();
//        $avatars = LectureShareInfo::orderBy('id', 'Desc')->lists('lecture_share_info.friend_id');
        return $avatars;
    }
                            
                                    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
最终答案: