On this page
搜索用户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();
}