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

搜索用户api


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

php
use app\common\model\User as UserModel;
...
// 搜索用户
public function user(){
    (new SearchValidate())->goCheck();
    $list = (new UserModel())->Search();
    return self::showResCode('获取成功',['list'=>$list]);
}

route层:route\route.php

php
Route::group('api/:v1/',function(){
	// 搜索用户
    Route::post('search/user', 'api/v1.Search/user');
});

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

php
// 搜索用户
public function Search(){
    // 获取所有参数
    $param = request()->param();
    return $this->where('username','like','%'.$param['keyword'].'%')->page($param['page'],10)->hidden(['password'])->select();
}