• This repository has been archived on 04/Oct/2022
  • Stars
    star
    121
  • Rank 293,042 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EU VAT library for Laravel

HEADS UP I suggest using ibericode/vat directly until #22 is tackled. Working with Laravel is not on my priority list so it would require someone else to send in a PR.

Laravel VAT

Build Status Software License

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 EU member state using ibericode/vat-rates.
  • 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

Installation

You can install this package via Composer:

composer require dannyvankooten/laravel-vat

The package will automatically register itself.

Usage

Check out the ibericode/vat README for general usage of this package.

Facades

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;

// 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

By default, VAT rates are cached for 24 hours using the default cache driver.

Validation

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

Localization

You can translate the validation error message by Using Translation Strings As Keys for the following strings:

resources/lang/de.json

{
    "The :attribute must be a valid VAT number.": "Your translation for the VatNumber Rule",
    "The :attribute must be a valid country.": "Your translation for the Country Rule"
}

License

MIT licensed.

More Repositories

1

AltoRouter

PHP routing class. Lightweight yet flexible. Supports REST, dynamic and reversed routing.
PHP
1,215
star
2

PHP-Router

Simple PHP Router class (supports REST and reverse routing)
PHP
564
star
3

vat

Go package for dealing with EU VAT. Does VAT number validation & rates retrieval.
Go
112
star
4

grender

Go package for easily rendering JSON/XML data and HTML templates
Go
95
star
5

plugin-endpoints

Register URL endpoints for which only certain WordPress plugins are enabled.
PHP
84
star
6

1brc

C11 implementation of the 1 Billion Rows Challenge. 1๏ธโƒฃ๐Ÿ๐ŸŽ๏ธ Runs in ~1.6 seconds on my not-so-fast laptop CPU w/ 16GB RAM.
C
82
star
7

populate.js

Populate form fields from a JSON object.
HTML
70
star
8

pepper-lang

The Pepper Programming Language
C
59
star
9

extemplate

Wrapper package for Go's template/html to allow for easy file-based template inheritance.
Go
57
star
10

wp-plugin-profiler

Basic profiler for WordPress plugins. Measures response times with and without a given plugin activated.
PHP
55
star
11

goseo

command line tool to assess readability and SEO score for any HTML document or web page
Go
55
star
12

change-username

A WordPress plugin to change usernames
PHP
53
star
13

nederlang

Nederlandse programmeertaal ๐Ÿ‡ณ๐Ÿ‡ฑ. Geรฏnterpreteerd en met dynamische types. Met bytecode compiler en virtuele machine, in Rust.
Rust
35
star
14

advent-of-code

Solutions for Advent of Code puzzles. In C, C++, Python, Rust and Golang. All years.
C
33
star
15

monkey-c-monkey-do

C implementation of the Monkey programming language. Repository moved to Sourcehut.
C
32
star
16

gozer

Fast, opinionated and simple static site generator in a single static binary. Mirrored from https://git.sr.ht/~dvko/gozer.
Go
30
star
17

wp-cdn-loader

Loads WordPress assets from a CDN instead of of local server.
PHP
22
star
18

moneybird-go

A Go client library for Moneybird
Go
18
star
19

unja

Template engine for C, inspired by Jinja and Liquid
C
13
star
20

smtp-mailer

A WordPress plugin that configures `wp_mail` to use SMTP.
PHP
13
star
21

dutchfirecalc.nl

Source code for dutchfirecalc.nl
Jupyter Notebook
10
star
22

respond

Go package for easily replying to HTTP requests with common response types.
Go
10
star
23

www.dannyvankooten.com

My personal website, managed by Gozer.
Jupyter Notebook
6
star
24

www.dvk.co

Site repository for my personal blog
Jupyter Notebook
4
star
25

dotfiles

My dotfiles
Shell
4
star
26

moneybird-belastingdienst

Makkelijker kunnen zij het niet maken, wij wel.
HTML
2
star
27

top2000spotify

Maakt 'n Spotify playlist van je Top 2000 lijstje (of die van iemand anders).
JavaScript
2
star
28

stand

Stand is a periodic reminder to stand up from your desk
C
2
star
29

argos-crypto-watch

Lightweight C program for monitoring cryptocurrency price and volume changes in Argos.
C
1
star
30

pi-volume-control

Remote volume control for my Pi over HTTP
C
1
star
31

advent-of-code-2021

My solutions for Advent of Code 2021, in Python this time.
Python
1
star
32

advent-of-code-2019

My solutions for Advent of Code 2019, in Rust.
Rust
1
star
33

top-websites-compression

Researching compression applied by the top 10.000 websites
HTML
1
star
34

cnake

Snake in your terminal. In C, no dependencies.
C
1
star