Skip to content
关注公众号,获取新课通知
【重要通知】uniapp实战社区交友交流群更换为:602180461,靓仔/靓女可以重新申请加入哦~

关注列表api


controller层:application\api\controller\v1\User.php

php
// 关注列表
public function follows(){
    (new UserValidate())->goCheck('getfollows'); 
    $list = (new UserModel())->getFollowsList();
    return self::showResCode('获取成功',['list'=>$list]);
}

route层:route\route.php

php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
	// 关注列表
    Route::get('follows/:page','api/v1.User/follows');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);

validate层:

php
protected $scene = [
    'getfollows'=>['page'],
];

model层:application\common\model\User.php

php
// 关联关注列表
public function follows(){
    return $this->belongsToMany('User','Follow','follow_id','user_id');
}
// 获取当前用户关注列表
public function getFollowsList(){
    // 获取所有参数
    $params = request()->param();
    // 获取用户id
    $userid = request()->userId;
    $follows = $this->get($userid)->follows()->page($params['page'],10)->select()->toArray();
    return $this->filterReturn($follows);
}