PHP code example of ialpro / bundesland

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.
}

$this->app->singleton(
    \Ialpro\Bundesland\Contracts\PostalCodeProvider::class,
    App\PostalCodes\CompanyProvider::class,
);

return [
    'provider' => [
        'driver' => 'zippopotam',
        'country' => env('BUNDESLAND_COUNTRY', 'de'),
        'base_url' => env('BUNDESLAND_BASE_URL', 'https://api.zippopotam.us'),
        'timeout' => (int) env('BUNDESLAND_TIMEOUT', 5),
        'connect_timeout' => (int) env('BUNDESLAND_CONNECT_TIMEOUT', 2),
        'retries' => (int) env('BUNDESLAND_RETRIES', 2),
    ],
    'cache' => [
        'enabled' => (bool) env('BUNDESLAND_CACHE_ENABLED', true),
        'ttl' => (int) env('BUNDESLAND_CACHE_TTL', 86400),
    ],
    'city' => [
        'transliterate' => (bool) env('BUNDESLAND_CITY_TRANSLITERATE', true),
    ],
    'api' => [
        'enabled' => (bool) env('BUNDESLAND_ENABLE_API', false),
        'prefix' => env('BUNDESLAND_API_PREFIX', 'api/bundesland'),
        'middleware' => ['api', 'throttle:60,1'],
    ],
];
bash
php artisan vendor:publish --tag=bundesland-config