ddeboer/vatin
Validate EU VAT identification numbers and check their status via the VIES service. Provides simple PHP utilities to format, validate, and verify VATINs for customers and companies, making it easy to add VAT checks to invoicing and checkout flows.
FormRequest, Validator) or business logic layers (e.g., InvoiceService).Validator facade (custom rule) or as a standalone service.StoreCustomerRequest) or API validation (e.g., ValidateVatNumber rule).bind(VatValidator::class, function ($app) { ... }))."DE123456789" or "IT01234567890").VatValidated event) or policies (e.g., VatPolicy::validate()).App\Exceptions\Handler) maps these to user-friendly responses (e.g., API errors).assertValid.use ddeboer\vatin\VatNumber;
use Illuminate\Contracts\Validation\Rule;
class ValidateVatNumber implements Rule {
public function passes($attribute, $value) {
try {
$vat = new VatNumber($value);
return $vat->isValid();
} catch (\InvalidArgumentException $e) {
return false;
}
}
}
Usage in FormRequest:
public function rules() {
return ['vat_number' => ['required', new ValidateVatNumber]];
}
$this->app->bind(VatValidator::class, function ($app) {
return new class {
public function validate(string $vatNumber): bool {
$vat = new \ddeboer\vatin\VatNumber($vatNumber);
return $vat->isValid();
}
};
});
Usage in controllers/services:
public function store(Request $request) {
$validator = resolve(VatValidator::class);
if (!$validator->validate($request->vat_number)) {
// Handle error
}
}
Customer):
public function setVatNumberAttribute($value) {
$vat = new \ddeboer\vatin\VatNumber($value);
if (!$vat->isValid()) {
throw new \InvalidArgumentException("Invalid VAT number");
}
$this->attributes['vat_number'] = $vat->getNormalized();
}
composer require ddeboer/vatin).VatService) to centralize logic.vat_number column in customers table).ddeboer/vatin for EU VAT rule changes (e.g., new country codes, format updates).update command or GitHub Dependabot for alerts.null, empty string, non-EU formats).ValidateVatNumber rule in StoreOrderRequest").["vat_number" => "INVALID", "country" => "DE", "error" => "Checksum failed"]).How can I help you explore Laravel packages today?