Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Bpost Address Webservice Laravel Package

spatie/bpost-address-webservice

PHP wrapper for bpost’s Address Webservice. Create Address objects and validate Belgian addresses, receiving normalized fields plus warnings/errors/issue lists you can inspect and act on. Useful for checkout forms and address cleanup.

View on GitHub
Deep Wiki
Context7

An API wrapper for bpost's address webservice

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

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.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/bpost-address-webservice

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.

Postcardware

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, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport