public function checkLogin (Request $request)
{
$status = 0;
$result = 'Default value';
$ data = $request->param();
$result = validate(UserValidate::class)->check($data);
// If it is found during the test that the field verification fails, the execution will not proceed.
If($result){
$result = 'Verification successful';
$status = 1;
#} Else {
# Validate ()-& GT; Geterror ();
##} return ['status'=>$status, 'message'=>$result, 'data'=>$data]; }
<?phpnamespace app\validate;use think\Validate;class User extends Validate{
protected $rule = [
'name|username' => 'require' ,
'password|password' => 'require',
'verify|verification code' => 'require|captcha',
]; protected $ message = [
'name|Username.require' => 'Name must be filled in',
'password|Password.require' => 'Password required',
'verify.require' => 'Verification code must be filled in',
'verify.captcha' => 'Verification code error',
];}
============================================ =======================
<?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 = 'Default value';
$data = $request->param(); = new UserValidate; // $result = $validate->check($data); if(UserFacade::check($data)){
$result = 'Verification successful';
$status = 1; 'message'=>$result, 'data'=>$data];
}}
Customized message None display