- Notifications
You must be signed in to change notification settings - Fork7
Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux
License
pixelpeter/laravel5-isocodes-validation
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simple Laravel 5 wrapper for theIsoCodes Validation library from ronanguilloux.
For aLaravel 8 compatible version please usehttps://github.com/pixelpeter/laravel-isocodes-validation
composer require pixelpeter/laravel5-isocodes-validation
(not needed starting with v2.x because of auto discovery)
Add the service provider inapp/config/app.php
'provider' => [ ...Pixelpeter\IsoCodesValidation\IsoCodesValidationServiceProvider::class, ...];
// Checking out your e-commerce shopping cart?$payload = ['creditcard' =>'12345679123456'];$rules = ['creditcard' =>'creditcard'];$validator = Validator::make($payload,$rules);
Some rules need a reference to be validated against (e.g.country forzipcode).
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);
(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']);
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".
Refer toIsoCodes Validation library for more examples and documentation.
Run the tests with:
vendor/bin/phpunit
GNU General Public License v3.0 only. Please seeLicense File for more information.
About
Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.