PHP code example of dannyvankooten / laravel-vat

1. Go to this page and download the library: Download dannyvankooten/laravel-vat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dannyvankooten / laravel-vat example snippets


use DvK\Laravel\Vat\Facades\Rates;
use DvK\Laravel\Vat\Facades\Validator;
use DvK\Laravel\Vat\Facades\Countries;

// Get current standard VAT rate for a country
Rates::country('NL'); // 21.00

// Get reduced VAT rate
Rates::country('NL', 'reduced'); // 6.00

// Get reduced VAT rate on a given Date
Rates::country('NL', 'reduced', new \DateTime('2005-01-01')); // 19.00

// Get an array of rates in country code => rates format
Rates::all(); 

// Validate a VAT number by both format and existence
Validator::validate('NL50123'); // false

// Validate VAT number by format only
Validator::validateFormat('NL203458239B01'); // true

// Validate VAT number by existence (uses a remote HTTP service)
Validator::validateExistence('NL203458239B01') // false

// Get array of ISO-3316 country codes and country names
Countries::all(); // array of country codes + names

// Get name of country by ISO-3316 code
Countries::name('NL') // Netherlands

// Get array of EU country codes + names
Countries::europe(); // array of EU country codes + names

// Check if ISO-3316 code is in EU
Countries::inEurope('NL'); // true

// Get ISO-3316 code by IP address geo-location
Countries::ip('8.8.8.8'); // US

use Illuminate\Http\Request;

class Controller {

    public function foo(Request $request)
    {
        $request->validate([
            'vat_number_field' => ['vat_number'],
            'country_code_field' => [ 'country_code' ],
        ]);
    }
}

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() ],
        ]);
    }
}