On this page
关注列表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);
}