Looking to hire Laravel developers? Try LaraJobs

laravel-euro-vat maintained by kfoobar

Description
A Laravel package for Euro VAT validation
Author
Last update
2026/04/01 23:51 (dev-main)
License
Downloads
9

Comments
comments powered by Disqus

Laravel EU VAT Validator

A Laravel package for validating EU VAT numbers, including local format validation and online validation against the EU VIES API.

Installation

Install the package via Composer:

composer require kfoobar/laravel-euro-vat

Publish the configuration file:

php artisan vendor:publish --provider="KFoobar\EuroVAT\EuroVATServiceProvider"

Configuration

The configuration file config/euro-vat.php allows you to set:

  • urls.number: Endpoint used when validating a VAT number online.
  • urls.status: Endpoint used for the VIES status check.
  • ttl.number: Cache lifetime in minutes for VAT validation results.
  • ttl.status: Cache lifetime in minutes for VIES status results.

Usage

The main service exposes:

  • validate(string $number, ?string $country = null): ?string
  • validateOffline(string $number, ?string $country = null): ?string
  • validateOnline(string $number, string $country): ?string
  • status(?string $country = null): bool

Using the Facade

Validate a VAT number:

use KFoobar\EuroVAT\Facades\EuroVAT;

EuroVAT::validate('SE123456789012');
EuroVAT::validateOffline('SE123456789012');
EuroVAT::validateOnline('123456789012', 'SE');
EuroVAT::validate('123456789012', 'SE');
EuroVAT::status('SE');

validate() is the default entrypoint and performs online validation.

validateOffline() only performs the local VAT format check. No external HTTP request is made.

validateOnline() sends the provided VAT number and country code directly to the EU VIES API and caches the response. It does not normalize or pre-validate the VAT number locally.

Using the Validation Rule

use KFoobar\EuroVAT\Rules\VatId;

$request->validate([
    'vat_number' => ['required', new VatId('SE')],
]);

Using the vat_id Validator Extension

$request->validate([
    'vat_number' => 'required|vat_id:SE',
]);

Contributing

Contributions are welcome!

License

The MIT License (MIT). Please see License File for more information.