The Belgian mail service, Bpost, has an API to
Create an \Spatie\BpostAddressWebservice\Address
, and validate it.
$addressValidator = AddressValidator::create();
$address = Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]);
$validatedAddress = $addressValidator->validate($address);
The validated address can contain errors and warnings. If it has any error or warning, we say that it has issues.
$validatedAddress->hasErrors(); // false
$validatedAddress->hasWarnings(); // true
$validatedAddress->hasIssues(); // true
An array of errors, warnings, or issues can be retrieved from the validated address.
$validatedAddress->errors(); // []
$validatedAddress->warnings()[0]->attribute(); // 'municipalityName'
$validatedAddress->warnings()[0]->message(); // 'anomaly_in_field'
$validatedAddress->issues()[0]->attribute(); // 'municipalityName'
$validatedAddress->issues()[0]->message(); // 'anomaly_in_field'
A validated addresses' attributes can be retrieved.
$validatedAddress->streetName; // 'Samberstraat'
$validatedAddress->streetNumber; // '69'
$validatedAddress->boxNumber; // ''
$validatedAddress->postalCode; // '2060'
$validatedAddress->municipalityName; // 'Antwaarpe'
$validatedAddress->country; // 'BELGIE'
$validatedAddress->toArray();
// [
// 'streetName' => 'SAMBERSTRAAT',
// 'streetNumber' => '69',
// 'boxNumber' => '',
// 'postalCode' => '2060',
// 'municipalityName' => 'ANTWERPEN',
// 'country' => 'BELGIE',
// ]
You can also validate up to 100 addresses at a time. An array of ValidatedAddresses
will be returned.
$addressValidator = AddressValidator::create();
$validatedAddresses = $addressValidator->validateMany([
Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]),
// ...
]);
Address webservice documentation is available on bpost.be.
You can install the package via composer:
composer require spatie/bpost-address-webservice
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
We publish all received postcards on our company website.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
The MIT License (MIT). Please see License File for more information.