PHP code example of spatie / bpost-address-webservice
1. Go to this page and download the library: Download spatie/bpost-address-webservice library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / bpost-address-webservice example snippets
$addressValidator = AddressValidator::create();
$address = Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]);
$validatedAddress = $addressValidator->validate($address);
$validatedAddress->hasErrors(); // false
$validatedAddress->hasWarnings(); // true
$validatedAddress->hasIssues(); // true
$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'
$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',
// ]
$addressValidator = AddressValidator::create();
$validatedAddresses = $addressValidator->validateMany([
Address::create([
'streetName' => 'Samberstraat',
'streetNumber' => '69',
'boxNumber' => 'D',
'postalCode' => '2060',
'municipalityName' => 'Antwaarpe',
'country' => 'BELGIE',
]),
// ...
]);