Created
October 23, 2019 03:17
-
-
Save diaolizhi/d8bf6e3e0e94cf8344aca63c1b036fac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function fans($userId) | |
{ | |
// 1.1 检查用户是否存在 | |
UserModel::mustExist(['id' => $userId, 'status' => BaseModel::ENABLED], '用户不存在或已被封禁'); | |
// 2.1 查 user_follow 表, 找出跟当前用户相关的记录 | |
$userFollows = UserFollowModel::where(['followed_user_id' => $userId])->paginate(request('pagesize', 20)); | |
// 2.2 查询本次需要查询的 user_id | |
$ids = array_map(function ($item) { | |
return $item->user_id; | |
}, $userFollows->items()); | |
// 3.1 根据刚才得到的 user_id 查询 user | |
$users = UserModel::whereIn('id', $ids)->get()->toArray(); | |
// 4.1 创建 LengthAwarePaginator 对象 | |
$result = new LengthAwarePaginator($users, $userFollows->total(), $userFollows->perPage(), $userFollows->currentPage()); | |
return $this->success($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment