pixelpeter/laravel5-isocodes-validation
Composer 安装命令:
composer require pixelpeter/laravel5-isocodes-validation
包简介
Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux
关键字:
README 文档
README
A simple Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux.
For a Laravel 8 compatible version please use https://github.com/pixelpeter/laravel-isocodes-validation
Installation
Step 1: Install Through Composer
composer require pixelpeter/laravel5-isocodes-validation
Step 2: Add the Service Provider
(not needed starting with v2.x because of auto discovery)
Add the service provider in app/config/app.php
'provider' => [ ... Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider::class, ... ];
Usage
Simple examples
// Checking out your e-commerce shopping cart? $payload = [ 'creditcard' => '12345679123456' ]; $rules = [ 'creditcard' => 'creditcard' ]; $validator = Validator::make($payload, $rules);
Examples with reference parameter
Some rules need a reference to be validated against (e.g. country for zipcode).
Just pass the name of the field holding the reference to the rule.
// Sending letters to the Labrador Islands ? $payload = [ 'zipcode' => 'A0A 1A0', 'country' => 'CA' ]; $rules = [ 'zipcode' => 'zipcode:country' ]; $validator = Validator::make($payload, $rules); // Publishing books? $payload = [ 'isbn' => '2-2110-4199-X', 'isbntype' => 13 ]; $rules = [ 'zipcode' => 'isbn:isbntype' ]; $validator = Validator::make($payload, $rules);
Example with arrays and dot notation
(added in v3.x)
As suggested by @otr-tomek I've added support for all validation methods using arrays in dot notation as an input.
$payload = [ 'data' => [ [ 'country' => 'DE', 'zipcode' => 63741 ], [ 'country' => 'AT', 'zipcode' => 1180 ] ] ]; $validator = Validator::make($payload, [ 'data.*.zipcode' => 'zipcode:data.*.country' ]);
Validation error messages
Error messages can contain the name and value of the field and the value of the reference
$payload = [ 'phonenumber' => 'invalid', 'country' => 'GB' ]; $rules = [ 'phonenumber' => 'phonenumber:country' ]; $validator = Validator::make($payload, $rules); print $validator->errors()->first(); // The value "invalid" of phonenumber is not valid for "GB".
More Examples
Refer to IsoCodes Validation library for more examples and documentation.
Testing
Run the tests with:
vendor/bin/phpunit
License
GNU General Public License v3.0 only. Please see License File for more information.
pixelpeter/laravel5-isocodes-validation 适用场景与选型建议
pixelpeter/laravel5-isocodes-validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 87.76k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2016 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「laravel」 「iso」 「isocode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pixelpeter/laravel5-isocodes-validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pixelpeter/laravel5-isocodes-validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pixelpeter/laravel5-isocodes-validation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library providing ISO 639-1 data.
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
A CakePHP behavior to validate foreign keys
PHP Validator for stuff.
统计信息
- 总下载量: 87.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 23
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2016-05-22