On this page
指定用户下的所有文章api
controller层:application\api\controller\v1\User.php
php
// 用户发布文章列表
public function Allpost(){
(new UserValidate())->goCheck('allpost');
$list = (new UserModel())->getAllPostList();
return self::showResCode('获取成功',['list'=>$list]);
}
route层:route\route.php
php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
...
// 获取指定用户下的所有文章(含隐私)
Route::get('user/post/:page', 'api/v1.User/Allpost');
...
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);
validate层:application\common\validate\UserValidate.php
php
protected $rule = [
'page'=>'require|integer|>:0',
];
protected $scene = [
...
'allpost'=>['page'],
];
model层:application\common\model\User.php
php
// 获取指定用户下所有文章
public function getAllPostList(){
$params = request()->param();
// 获取用户id
$user_id=request()->userId;
return $this->get($user_id)->post()->with([
'user'=>function($query){
return $query->field('id,username,userpic');
},'images'=>function($query){
return $query->field('url');
},'share'])->page($params['page'],10)->select();
}