See ibericode/vat-bundle for a Symfony version of this package.
laravel-vat is a package that contains the Laravel related wiring code for ibericode/vat, helping you deal with VAT legislation for businesses based in the EU.
- Fetch (historical) VAT rates for any European member state using jsonvat.com
- Validate VAT numbers (by format, existence or both)
- Validate ISO-3316 alpha-2 country codes
- Determine whether a country is part of the EU
- Geolocate IP addresses
You can install this package via Composer:
composer require dannyvankooten/laravel-vat
The package will automatically register itself.
Check out the ibericode/vat README for general usage of this package.
You can use facades to retrieve an instance of the classes provided by ibericode/vat.
use DvK\Laravel\Vat\Facades\Rates;
use DvK\Laravel\Vat\Facades\Validator;
use DvK\Laravel\Vat\Facades\Countries;
Rates::country('NL'); // 21
Rates::country('NL', 'reduced'); // 6
Rates::country('NL', 'reduced', new \DateTime('2005-01-01')); // 19
Rates::all(); // array in country code => rates format
Validator::validate('NL50123'); // false
Validator::validateFormat('NL203458239B01'); // true (checks format)
Validator::validateExistence('NL203458239B01') // false (checks existence)
Validator::validate('NL203458239B01'); // false (checks format + existence)
Countries::all(); // array of country codes + names
Countries::name('NL') // Netherlands
Countries::europe(); // array of EU country codes + names
Countries::inEurope('NL'); // true
Countries::ip('8.8.8.8'); // US
By default, VAT rates are cached for 24 hours using the default cache driver.
The package registers two new validation rules.
vat_number
The field under validation must be a valid and existing VAT number.
country_code
The field under validation must be a valid ISO-3316 alpha-2 country code.
use Illuminate\Http\Request;
class Controller {
public function foo(Request $request)
{
$request->validate([
'vat_number_field' => ['vat_number'],
'country_code_field' => [ 'country_code' ],
]);
}
}
Alternatively, you can also use the Rule
objects directly.
use Illuminate\Http\Request;
use DvK\Laravel\Vat\Rules;
class Controller {
public function foo(Request $request)
{
$request->validate([
'vat_number_field' => [ new Rules\VatNumber() ],
'country_code_field' => [ new Rules\Country() ],
]);
}
}