Validata 参数校验层
独立验证 自定义错误信息
make
方法直接传入验证规则(数组),batch方法批量验证数据(数组)
check
方法传入需要验证的数据(数组)
$rule = [
'name' => 'require|max:25',
'age' => 'number|between:1,120',
'email' => 'email',
];
$msg = [
'name.require' => '名称必须',
'name.max' => '名称最多不能超过25个字符',
'age.number' => '年龄必须是数字',
'age.between' => '年龄必须在1~120之间',
'email' => '邮箱格式错误',
];
$data = [
'name' => 'thinkphp',
'age' => 121,
'email' => 'thinkphp@qq.com',
];
$validate = Validate::make($rule)->message($msg);
$result = $validate->batch()->