PHPackages                             cube-nl/postcode-nl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cube-nl/postcode-nl

ActiveLibrary[API Development](/categories/api)

cube-nl/postcode-nl
===================

Postcode.nl API

1.0.2(1y ago)0930↓25%BSD-3-ClausePHPPHP ^8.1CI failing

Since Apr 2Pushed 1y ago3 watchersCompare

[ Source](https://github.com/cubenl/postcode-nl-api)[ Packagist](https://packagist.org/packages/cube-nl/postcode-nl)[ RSS](/packages/cube-nl-postcode-nl/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Postcode.nl Laravel Package
===========================

[](#postcodenl-laravel-package)

A Laravel package that integrates with the [Postcode.nl API](https://www.postcode.nl/en/address-api) to look up Dutch addresses based on postcode and house number. This package provides API routing, local caching in your database, and structured responses using Laravel resources.

This package supports Laravel 10 and 11. Tested with PHPUnit 10 and PHP 8.2+.

📦 Installation
--------------

[](#-installation)

```
composer require cube-nl/postcode-nl

```

⚙️ Configuration
----------------

[](#️-configuration)

Publish the config and translation files:

```
php artisan vendor:publish --tag=postcode-nl-config
php artisan vendor:publish --tag=postcode-nl-translations
php artisan vendor:publish --tag=postcode-nl-translationsmigrations
```

This will create:

- config/postcode-nl.php
- resources/lang/vendor/postcode-nl/en/messages.php
- databases/migrations/2025\_03\_06\_152822\_create\_addresses\_table.php

### .env Setup

[](#env-setup)

Add your Postcode.nl API credentials:

```
POSTCODEAPI_API_KEY=your-api-key #The api key
POSTCODEAPI_SECRET_KEY=your-secret-key #The api secret key
POSTCODEAPI_TABLE_NAME=your-secret-key #The table name used by the package default addresses
```

🔁 Routes
--------

[](#-routes)

The following route is registered automatically:

```
GET /api/address/autocomplete?zipCode=1234AB&houseNumber=12A
```

Response (if found):

```
{
  "success": true,
  "street": "Hoofdstraat",
  "city": "Amsterdam"
}
```

If not found an error is thrown:

```
{
  "success": false,
  "message": "No address was found with this zip code and house number." // translated string
}
```

🧠 Usage in Code
---------------

[](#-usage-in-code)

You can call the lookup service directly:

```
use Cubenl\PostcodeNL\PostcodeNL;

$address = PostcodeNL::lookup('1234AB', '12A');

if ($address) {
    echo $address->street;
}
```

Returns a PostcodeResource or null if not found.

📝 Validation Rule Example
-------------------------

[](#-validation-rule-example)

You can add the ValidPostcode validation rule in a request, for example:

```
