您的位置:首页 > 编程语言 > PHP开发

钱包农场 API 开发手记 七 绑定手机

2018-04-04 00:00 302 查看

检查手机用户是否存在

路由

routes/api.php

// 检查手机用户是否存在
$api->get('cellUser', 'UsersController@showByCell')
->name('api.user.cellshow');


请求验证类

php artisan make:request Api/CellUserRequest

return [
'cellphone' => 'required|regex:/^1[3456789]\d{9}$/',
];


控制器

/**
* 根据手机号获取用户
*
* @param CellUserRequest $request
* @return bool
*/
public function showByCell(CellUserRequest $request)
{
$user = User::where('cellphone', $request->cellphone)->first();
if(!$user) {
$this->response->noContent();
}
return $this->response->array(['cellphone'=>$user->cellphone]);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Laravel