dannyvankooten / laravel-vat
2.0.7
2022-05-06 13:57 UTC
Requires
- php: >=7.1
- ibericode/vat: ^1.2
- illuminate/contracts: 5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*
- illuminate/support: 5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*
Requires (Dev)
- orchestra/testbench: ^3.7
- phpunit/phpunit: ^6.3|^7.0|^8.5
README
注意 我建议在解决#22问题之前直接使用ibericode/vat。由于与Laravel合作不是我的优先事项,因此需要其他人提交PR。
Laravel VAT
有关此包的Symfony版本,请参阅ibericode/vat-bundle。
laravel-vat是一个包含ibericode/vat相关连接代码的包,帮助您处理基于欧盟的企业的增值税法规。
- 使用ibericode/vat-rates获取任何欧盟成员国的(历史)增值税率。
- 验证增值税号(格式、存在或两者兼有)
- 验证ISO-3316 alpha-2国家代码
- 确定国家是否属于欧盟
- 地理定位IP地址
安装
您可以通过Composer安装此包
composer require dannyvankooten/laravel-vat
该包将自动注册自己。
使用方法
有关此包的一般用法,请参阅ibericode/vat README。
外观
您可以使用外观来获取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
默认情况下,增值税率使用默认缓存驱动程序缓存24小时。
验证
此包注册了两个新的验证规则。
vat_number
验证字段必须是有效且存在的增值税号。
country_code
验证字段必须是有效的ISO-3316 alpha-2国家代码。
use Illuminate\Http\Request; class Controller { public function foo(Request $request) { $request->validate([ 'vat_number_field' => ['vat_number'], 'country_code_field' => [ 'country_code' ], ]); } }
或者,您也可以直接使用Rule
对象。
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() ], ]); } }
本地化
您可以通过使用翻译字符串作为键将以下字符串的验证错误消息进行翻译
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"
}