public function checkLogin (Request $request)
{
$status = 0 ;
$result = '默认值';
$data = $request->param();
$result = validate(UserValidate::class)->check($data);
//测试中发现 字段验证不通过 就不往下执行了
if($result){
$result = '验证成功';
$status = 1 ;
}else{
validate()->getError();
}
return ['status'=>$status, 'message'=>$result, 'data'=>$data];
}
冰点儿2020-04-29 22:07:26
<?phpnamespace app\validate;use think\Validate;class User extends Validate{
protected $rule = [
'name|用户名' => 'require',
'password|密码' => 'require',
'verify|验证码' => 'require|captcha',
]; protected $message = [
'name|用户名.require' => '名称必须填写',
'password|密码.require' => '密码必须',
'verify.require' => '验证码必须填写',
'verify.captcha' => '验证码错误',
];}
================================================================
<?php
namespace app\facade;
use think\Facade;/*** */
class User extends Facade{
protected static function getFacadeClass()
{
return 'app\validate\User';
}
}
============================================================
public function checkLogin (Request $request) {
$status = 0 ;
$result = '默认值';
$data = $request->param(); // $validate = new UserValidate; // $result = $validate->check($data); if(UserFacade::check($data)){
$result = '验证成功';
$status = 1 ;
}else{ $result = UserFacade::getError();
}
return ['status'=>$status, 'message'=>$result, 'data'=>$data];
}}
自定义的message 没有显示出来