Looking to hire Laravel developers? Try LaraJobs

laravel-postcode maintained by mmerlijn

Description
Laravel postcode nl helper package
Author
Last update
2025/11/21 07:42 (dev-master)
License
Links
Downloads
49

Comments
comments powered by Disqus

Laravel Postcode

Installation

Install package
composer require mmerlijn/laravel-postcode
Optional Publish config file (for customisation)
php artisan vendor:publish --provider="mmerlijn\LaravelPostcodeServiceProvider" --tag="config"

database_connection_name => default: mysql_postcode
postcode_table_name => default: postcode_nl
postcode_table_not_found =>default: postcode_not_found

route.prefix    => default: postcode
route.middleware => default: ['web']

Usage

Postcode request

POST: ../postcode/getAddress {city:...,building:...}

//Required: city and building

Response

//on success example
status:200
data:{
    "postcode": "1187LS"
    "nr": "3 a"
    "building_nr": "3"
    "building_addition": "a"
    "street": "Westwijkplein"
    "city": "Amstelveen"
    "province": "Noord-Holland"
    "lat": "52.281458330925"
    "long": "4.8261185828603"
    "success": true
    "error": null
}
//on not found failure example
status:200
data:{
    "postcode": "1187LS"
    "nr": "3 a"
    "building_nr": "3"
    "building_addition": "a"
    "street": ""
    "city": ""
    "province": ""
    "lat": ""
    "long": ""
    "success": false
    "error": 'Postcode not found'
}
//on invalid request
status:422
Usual laravel validation errors

Usefull methods

Scopes

$p = Postcode::getAddress($city,$building)->first();

Static methods

$c = Postcode::getCity($postcode); //returns name of city or empty string

$c = Postcode::getCityCoordinates($city); // return array ['lat'=>...,'long'=>...]
$c = Postcode::getPostcodeCoordinates($postcode); // return array ['lat'=>...,'long'=>...]
$c = Postcode::getCoordinates(postcode/city);  // return array ['lat'=>...,'long'=>...]