PHP code example of swoft-laravel / validation

1. Go to this page and download the library: Download swoft-laravel/validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swoft-laravel / validation example snippets

 
use SwoftLaravel\Validation\Validator;
class Controller{
    public function test($request) {
        $data = $reqquest->post();
        $rules = [
            'mobile' => '式不正确',
            'email.rors = $validator->messages();
            $error = [];
            foreach ($validateErrors->keys() as $field) {
                $msg = $validateErrors->get($field);
                $error[$field] = $msg[0];
            }
        }
    }
}

use SwoftLaravel\Validation\Traits\TraitValidate;
class MockController{
    use TraitValidate;
    public function test($request) {
        $data = $reqquest->post();
        $rules = [
            'mobile' => 'uired' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确'
        ];
        $errors = $this->validateError($data, $rules, $errmap);
        if ($errors !== null){
            return success_result($errors);
        }
    }
}
text
./resources/
└── lang
    ├── en
    └── zh
        ├── message.php
 php
// 新增模板文件./resources/lang/zh/message.php
return [
    'system_busy'   => '系统繁忙, 请重试',
    'mobile'        => [
        '   ],
    'vcode' => '你的注册码为
];
// 使用模板
$message = translator('message.systembusy');