danielebarbaro / laravel-vat-eu-validator
A simple package that validates EU VAT numbers against the central ec.europa.eu database
Package info
github.com/danielebarbaro/laravel-vat-eu-validator
pkg:composer/danielebarbaro/laravel-vat-eu-validator
Fund package maintenance!
Requires
- php: ^8.2
- ext-openssl: *
- ext-soap: *
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- driftingly/rector-laravel: ^2.0
- friendsofphp/php-cs-fixer: ^3.59
- orchestra/testbench: ^v10.11.0|^v11.0.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^11.5.50|^12.0|^13.0
- rector/rector: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-13 10:14:01 UTC
README
Laravel VAT EU VALIDATOR
laravel-vat-eu-validator is a package inspired by vat.php to validate a VAT number for businesses based in Europe.
For Laravel 10, 11, 12, 13 use tag 3.x
Note on Laravel 10 and 11. Both branches are end of life and every released version is flagged by a Composer security advisory, so Composer 2.9 and later refuse to install them by default. The package constraints still allow them, but CI only covers Laravel 12 and 13. If you are still on Laravel 10 or 11, plan an upgrade.
For Laravel 10, 11, 12 use tag 2.x (legacy SOAP-only)
For Laravel 8, 9 use tag 1.20
For Laravel 5, 6, 7 use tag 0.5.4
What's new in v3.0
- REST Client support: an alternative to the traditional SOAP client, using the official European Commission REST APIs
- Strategy Pattern architecture: ViesClientInterface interface with ViesSoapClient and ViesRestClient implementations
- Publishable configuration file: choose which client to use and configure its parameters
- Restructured test suite: separation between unit and functional tests
- PHP 8.4 and 8.5 support
Installation
You can install the package via composer:
composer require danielebarbaro/laravel-vat-eu-validator
The package will automatically register itself.
Configuration
VIES Client Configuration
The package supports multiple VIES clients for VAT validation:
- SOAP Client (default): Uses the traditional SOAP API
- REST Client: Uses the modern REST API
To customize the client configuration, publish the configuration file:
php artisan vendor:publish --tag=laravel-vat-eu-validator-config
This will create a config/vat-validator.php file where you can configure which client to use:
<?php use Danielebarbaro\LaravelVatEuValidator\Vies\ViesRestClient; use Danielebarbaro\LaravelVatEuValidator\Vies\ViesSoapClient; return [ // Select which client to use for VIES validation // Available: ViesSoapClient::CLIENT_NAME, ViesRestClient::CLIENT_NAME 'client' => ViesSoapClient::CLIENT_NAME, // Default: SOAP 'clients' => [ ViesSoapClient::CLIENT_NAME => [ 'timeout' => 10, ], ViesRestClient::CLIENT_NAME => [ 'timeout' => 10, 'base_url' => ViesRestClient::BASE_URL, ], ], ];
Switching to REST Client
To use the REST client instead of SOAP, update your config/vat-validator.php:
'client' => ViesRestClient::CLIENT_NAME,
The REST client uses the official European Commission VIES REST API endpoints, which do not require authentication or API keys.
Customizing REST Client Configuration
You can customize the REST client timeout and base URL if needed:
'clients' => [ ViesRestClient::CLIENT_NAME => [ 'timeout' => 10, // seconds 'base_url' => env('VIES_REST_BASE_URL', ViesRestClient::BASE_URL), ], ],
By default, the client uses the official EU endpoint: https://ec.europa.eu/taxation_customs/vies/rest-api
Customizing Timeout
You can adjust the timeout for API requests:
'clients' => [ ViesSoapClient::CLIENT_NAME => [ 'timeout' => 30, // seconds ], ],
Usage
use Danielebarbaro\LaravelVatEuValidator\Facades\VatValidatorFacade as VatValidator; // Check VAT format and VIES existence VatValidator::validate('IT12345678901'); // Check VAT format VatValidator::validateFormat('IT12345678901'); // Check VAT existence VatValidator::validateExistence('IT12345678901');
Validation
The package registers three new validation rules.
vat_number
The field under validation must be a correctly formatted VAT number that also exists in VIES.
vat_number_exist
The field under validation must be a VAT number that exists in VIES.
vat_number_format
The field under validation must be a correctly formatted VAT number. VIES is not queried.
use Illuminate\Http\Request; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber()], ]); $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist()], ]); $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat()], ]); } }
Alternatively, import the rules instead of writing the fully qualified names.
use Illuminate\Http\Request; use Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber; use Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist; use Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [new VatNumber()], 'baz_field' => [new VatNumberExist()], 'qux_field' => [new VatNumberFormat()], ]); } }
Each rule can also be referenced by its string name.
use Illuminate\Http\Request; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => ['vat_number'], 'baz_field' => ['vat_number_format'], 'qux_field' => ['vat_number_exist'], ]); } }
Translations
Most of the displayed strings are defined in the vatEuValidator::validation translation files. The package ships with a few supported locales, but if yours is not yet included we would greatly appreciate a PR.
If not already published, you can edit or fill the translation files using php artisan vendor:publish --tag=laravel-vat-eu-validator-lang, this will copy our translation files to your app's vendor/laravelVatEuValidator "lang" path.
Testing
# Run unit tests composer test # Run functional tests (makes actual API calls) composer test-functional
For detailed testing documentation, see tests/README.md.
Upgrading from v2.x to v3.0
No changes needed if you use the package as-is
The package works out-of-the-box with SOAP as the default client, exactly as before.
If you were instantiating VatValidator or Client manually
// ❌ Before (v2.x) use Danielebarbaro\LaravelVatEuValidator\Vies\Client; $validator = new VatValidator(new Client()); // ✅ After (v3.0) use Danielebarbaro\LaravelVatEuValidator\Vies\ViesSoapClient; $validator = new VatValidator(new ViesSoapClient()); // Or with REST client use Danielebarbaro\LaravelVatEuValidator\Vies\ViesRestClient; $validator = new VatValidator(new ViesRestClient());
If you want to switch to the REST client
- Publish the configuration:
php artisan vendor:publish --tag=laravel-vat-eu-validator-config - Update
config/vat-validator.php:
'client' => ViesRestClient::CLIENT_NAME,
If your tests reference Vies\Client
Update references to ViesSoapClient or use ViesClientInterface for mocking.
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.
