danielebarbaro / laravel-vat-eu-validator
A simple package that validates EU VAT numbers against the central ec.europa.eu database
Fund package maintenance!
danielebarbaro
Requires
- php: ^8.0|^8.1|^8.2
- ext-soap: *
- illuminate/contracts: ^8.73|^9.2|^10.0|^11.0
- illuminate/support: ^v8.83.2|^9.2|^10.0|^11.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.3
- nunomaduro/collision: ^5.10|^6.0|^8.0
- nunomaduro/larastan: ^1.0|^2.0.1
- orchestra/testbench: ^6.22|^7.0|^8.0|^9.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.5
- dev-master
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-dependabot/github_actions/dependabot/fetch-metadata-2.0.0
- dev-dependabot/github_actions/ramsey/composer-install-3
- dev-dependabot/github_actions/ramsey/composer-install-2
- dev-feature/l9-php8-release
This package is not auto-updated.
Last update: 2024-03-28 06:56:21 UTC
README
laravel-vat-eu-validator is a package inspired from vat.php to validate a VAT number for businesses based in Europe.
For Laravel 5,6,7 use tag 0.5.4
Installation
You can install the package via composer:
composer require danielebarbaro/laravel-vat-eu-validator
The package will automatically register itself.
Usage
use Danielebarbaro\LaravelVatEuValidator\Facades\VatValidatorFacade as VatValidator; // Check VAT format and VIES existence VatValidator::validate('IT12345'); // Check VAT format VatValidator::validateFormat('IT12345678901'); // Check VAT existence VatValidator::validateExistence('IT12345678901');
Validation
The package registers two new validation rules.
vat_number
The field under validation must be a valid and existing VAT number.
vat_number_exist
The field under validation check id is an existing VAT number.
vat_number_format
The field under validation must be a valid VAT number.
use Illuminate\Http\Request; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => ['vat_number'], ]); $request->validate([ 'bar_field' => ['vat_number_exist'], ]); $request->validate([ 'bar_field' => ['vat_number_format'], ]); } }
Alternatively, you can also use the Rule
directly.
use Illuminate\Http\Request; use Danielebarbaro\LaravelVatEuValidator\Rules; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [ new Rules\VatNumber() ], 'bar_field' => [ new Rules\VatNumberExist() ], 'bar_field' => [ new Rules\VatNumberFormat() ], ]); } }
Translations
Just add and customize validation strings in lang/en/validation.php
...
'vat_number' => 'The :attribute must be a valid VAT number.',
'vat_number_format' => 'The :attribute must be write in a valid number format {country_name}{vat_number}.',
'vat_number_exist' => 'VAT number :attribute not exist.',
...
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email barbaro.daniele@gmail.com instead of using the issue tracker.
Credits
Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.