mmerlijn / laravel-postcode
Laravel postcode nl helper package
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.2
- mmerlijn/laravel-helpers: ~2.0
Requires (Dev)
- laravel/framework: ^11.x-dev
- orchestra/testbench: 9.x-dev
- phpunit/phpunit: ^11.0.1
This package is auto-updated.
Last update: 2025-02-17 22:33:20 UTC
README
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'=>...]