mouyong/validate base on illuminate/validate
v2.0.4
版本
2022-11-09
版本更新时间
394
安装
3
star
简介
适用于 webman 的 laravel validate
基于 illuminate/validate,在 laravel 框架外使用的 validate
安装
composer require mouyong/validate -vvv
文件翻译创建
./webman plugin:install mouyong/validate
or
php ./vendor/mouyong/validate/src/scripts/install.php
移除翻译文件
./webman plugin:uninstall mouyong/validate
or
php ./vendor/mouyong/validate/src/scripts/uninstall.php
基础用法
$data = [
'name' => 'Tinywan',
'age' => 24,
'email' => 'Tinywan@163.com'
];
/** @var \Illuminate\Contracts\Validation\Validator|\Illuminate\Contracts\Validation\Factory $validator */
$validator = validator($data, [
'name' => 'require|max:25',
'age' => 'require|number|between:1,120',
'email' => 'require|email'
], [
'name.require' => '名称必须',
'name.max' => '名称最多不能超过25个字符',
'age.require' => '年龄必须是数字',
'age.number' => '年龄必须是数字',
'age.between' => '年龄只能在1-120之间',
'email.require' => '邮箱必须是数字',
'email.email' => '邮箱格式错误'
]);
$validator->validate();
// 或者直接简写
validator()->validate($data, [
'name' => 'require|max:25',
'age' => 'require|number|between:1,120',
'email' => 'require|email'
], [
'name.require' => '名称必须',
'name.max' => '名称最多不能超过25个字符',
'age.require' => '年龄必须是数字',
'age.number' => '年龄必须是数字',
'age.between' => '年龄只能在1-120之间',
'email.require' => '邮箱必须是数字',
'email.email' => '邮箱格式错误'
]);
更多验证规则请阅读:http://laravel.com/docs/9.x/validation#available-validation-rules