Download the PHP package cube-nl/postcode-nl without Composer
On this page you can find all versions of the php package cube-nl/postcode-nl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cube-nl/postcode-nl
More information about cube-nl/postcode-nl
Files in cube-nl/postcode-nl
Informations about the package postcode-nl
Postcode.nl Laravel Package
A Laravel package that integrates with the Postcode.nl 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
⚙️ Configuration
Publish the config and translation files:
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
Add your Postcode.nl API credentials:
``
🔁 Routes
The following route is registered automatically:
Response (if found):
`
If not found an error is thrown:
🧠 Usage in Code
You can call the lookup service directly:
``
Returns a PostcodeResource or null if not found.
📝 Validation Rule Example
You can add the ValidPostcode validation rule in a request, for example:
🏠 House Number Parsing Explained
The lookup method supports house numbers with or without additions. For example:
- "12" → house number 12, no addition
- "12A" → house number 12, addition "A"
- "12-A" → house number 12, addition "-A"
If the format is invalid, an InvalidArgumentException will be thrown.
🗃️ Address Caching
When a valid address is retrieved, it will be stored locally in the addresses or custom configured name table. If the address already exists in the local DB, the API will not be called again.
✅ Running Tests
To run the test suite:
🤝 Contributing
If you’d like to improve this package, feel free to fork it and submit a pull request. Please include tests for new features.