PHP code example of cube-nl / postcode-nl

1. Go to this page and download the library: Download cube-nl/postcode-nl 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/ */

    

cube-nl / postcode-nl example snippets


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

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

use Cubenl\PostcodeNL\PostcodeNL;

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

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



namespace App\Http\Requests;


use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Cubenl\PostcodeNL\Rules\ValidPostcode;

class ExampleRequest extends FormRequest
{
    // ... (other request code) ...

    public function rules(): array
    {
        return [
            // ... (other rules) ...
            'postal_code' => [new ValidPostcode($this->input('house_number'))], //$value is the postal_code
            // ... (other rules) ...
        ];
    }
}
bash
php artisan vendor:publish --tag=postcode-nl-config
php artisan vendor:publish --tag=postcode-nl-translations
php artisan vendor:publish --tag=postcode-nl-translationsmigrations