1. Go to this page and download the library: Download ialpro/bundesland 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/ */
ialpro / bundesland example snippets
use Ialpro\Bundesland\Enums\LookupStatus;
use Ialpro\Bundesland\Facades\Bundesland;
$result = Bundesland::lookup('10115');
if ($result->status === LookupStatus::Success) {
echo $result->state; // Berlin
}
$state = Bundesland::stateByZip('20095'); // Hamburg or null when not found
$state = bundesland('80331', 'München'); // Bayern or null on any failure
$result = Bundesland::lookup('80331', 'München');
$result->status; // LookupStatus::Success
$result->city; // München (canonical provider spelling)
$result->state; // Bayern
$result->matchedCities; // all cities returned for this postcode
$message = match ($result->status) {
LookupStatus::Success => "State: {$result->state}",
LookupStatus::NotFound => 'Postal code not found.',
LookupStatus::CityMismatch => 'City does not match the postal code.',
};
use Ialpro\Bundesland\Exceptions\InvalidPostalCode;
use Ialpro\Bundesland\Exceptions\MalformedProviderResponse;
use Ialpro\Bundesland\Exceptions\PostalProviderUnavailable;
try {
$result = Bundesland::lookup($postalCode, $city);
} catch (InvalidPostalCode $exception) {
// Input is not exactly five digits.
} catch (PostalProviderUnavailable|MalformedProviderResponse $exception) {
// Retry, degrade gracefully, or report an upstream incident.
}