2017 © Pedro Peláez
 

library laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

image

pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  • Tuesday, February 6, 2018
  • by pixelpeter
  • Repository
  • 2 Watchers
  • 14 Stars
  • 8,947 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 5 Forks
  • 0 Open issues
  • 5 Versions
  • 24 % Grown

The README.md

Laravel 5 IsoCodes Validation

Latest Version on Packagist Total Downloads Software License Coverage Status Tests Fix PHP code style issues PHPStan dependabot-auto-merge, (*1)

A simple Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux., (*2)

For a Laravel 8 compatible version please use https://github.com/pixelpeter/laravel-isocodes-validation, (*3)

Installation

Step 1: Install Through Composer

``` bash composer require pixelpeter/laravel5-isocodes-validation, (*4)


### 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` ```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)., (*5)

Just pass the name of the field holding the reference to the rule., (*6)

// 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), (*7)

As suggested by @otr-tomek I've added support for all validation methods using arrays in dot notation as an input., (*8)

$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, (*9)

$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., (*10)

Testing

Run the tests with:, (*11)

vendor/bin/phpunit

License

GNU General Public License v3.0 only. Please see License File for more information., (*12)

The Versions

06/02 2018

dev-master

9999999-dev https://github.com/pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel validation iso isocode

25/12 2017

v2.0.0

2.0.0.0 https://github.com/pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel validation iso isocode

31/01 2017

v1.2.0

1.2.0.0 https://github.com/pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel validation iso isocode

24/01 2017

v1.1.0

1.1.0.0 https://github.com/pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel validation iso isocode

22/05 2016

v1.0

1.0.0.0 https://github.com/pixelpeter/laravel5-isocodes-validation

Laravel 5 wrapper for the IsoCodes Validation library from ronanguilloux

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

laravel validation iso isocode