Universal PostcodeApi for Laravel 6.x/7.x/8.x

Overview

Laravel PostcodeApi

Build Status Total Downloads Latest Stable Version MIT Licensed

Installation

Install this package with composer:

composer require nickurt/laravel-postcodeapi

Copy the config files for the api

php artisan vendor:publish --provider="nickurt\PostcodeApi\ServiceProvider" --tag="config"

Examples

Default - en_AU

$postCode10 = PostcodeApi::create('PostcodeApiComAu')->find('3066');

Default - en_GB

$postCode11 = PostcodeApi::create('GeoPostcodeOrgUk')->find('SW1A1AA');
$postCode12 = PostcodeApi::create('GetAddressIO')->find('SW1A1AA');
$postCode13 = PostcodeApi::create('IdealPostcodes')->find('SW1A1AA');
$postCode14 = PostcodeApi::create('PostcodesIO')->find('SW1A1AA');
$postCode15 = PostcodeApi::create('UkPostcodes')->find('SW1A1AA');

Default - en_US

$postCode16 = PostcodeApi::create('Algolia')->find('92270');
$postCode17 = PostcodeApi::create('Bing')->find('92270');
$postCode18 = PostcodeApi::create('Geocodio')->find('92270');
$postCode19 = PostcodeApi::create('Google')->find('92270');
$postCode20 = PostcodeApi::create('Here')->find('92270');
$postCode21 = PostcodeApi::create('LocationIQ')->find('92270');
$postCode22 = PostcodeApi::create('Mapbox')->find('92270');
$postCode23 = PostcodeApi::create('OpenCage')->find('92270');
$postCode24 = PostcodeApi::create('TomTom')->find('92270');

Default - fr_FR

$postCode25 = PostcodeApi::create('AdresseDataGouv')->find('75007');
$postCode26 = PostcodeApi::create('AdresseDataGouv')->findByPostcodeAndHouseNumber('75007', '5 Avenue Anatole France');

Default - nl_BE

$postCode27 = PostcodeApi::create('Pro6PP_BE')->find('1000');

Default - nl_NL

$postCode28 = PostcodeApi::create('ApiPostcode')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode29 = PostcodeApi::create('NationaalGeoRegister')->find('1118CP');
$postCode30 = PostcodeApi::create('NationaalGeoRegister')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode31 = PostcodeApi::create('PostcoDe')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode32 = PostcodeApi::create('PostcodeApiNu')->find('1118CP');
$postCode33 = PostcodeApi::create('PostcodeApiNu')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode34 = PostcodeApi::create('PostcodeData')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode35 = PostcodeApi::create('PostcodeNL')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode36 = PostcodeApi::create('PostcodesNL')->find('1118CP');
$postCode37 = PostcodeApi::create('PostcodesNL')->findByPostcodeAndHouseNumber('1118CP', '202');
$postCode38 = PostcodeApi::create('Pro6PP_NL')->find('1118CP');
$postCode39 = PostcodeApi::create('Pstcd')->find('1118CP');
$postCode40 = PostcodeApi::create('Pstcd')->findByPostcodeAndHouseNumber('1118CP', '202');

Route

Route::get('/{postCode}', function($postCode) {
    $postCode41 = PostcodeApi::create('PostcodeApiNu')->find($postCode);
    
    return Response::json($postCode25->toArray(), 200, [], JSON_PRETTY_PRINT);
});

Providers

AdresseDataGouv, Algolia, ApiPostcode, Bing, Geocodio, GeoPostcodeOrgUk, GetAddresIO, Google, Here, IdealPostcodes, LocationIQ, Mapbox, NationaalGeoRegister, OpenCage, postco.de, PostcodeApiComAu, PostcodeApiNu, PostcodeData, PostcodeNL, PostcodesIO, PostcodesNL, Pro6PP_BE, Pro6PP_NL, Pstcd, TomTom, UkPostcodes

Tests

composer test

Comments
  • Caching responses

    Caching responses

    Hello,

    Do you think it could be possible to have the responses cached for a specific period of time ? Maybe in a separate table or something, and have the API first check if the postcode is already cached and return the CACHED responses ?

    This could save a few roundtrips to any API provider and also could limit the number of the API requests -- therefore reducing costs.

    opened by niladam 5
  • Fix authoritative autoloader issues

    Fix authoritative autoloader issues

    This solves the authoritative mode of Composer not loading some classes

    • all providers are affected
    • This also runs the unit tests with an optimized, authoritative classmap, to check if it actually works (it'll explode if it's wrongly registered again)
    • Also moved the tests from the nickurt\PostcodeApi\tests namespace to the nickurt\PostcodeApi\Tests namespace, to be more in line with PSR-4.

    Fixes #19.

    opened by roelofr 3
  • Be able to set the http client to be used (unit testing purposes)

    Be able to set the http client to be used (unit testing purposes)

    Hi,

    It doesn't seem to be possible to set the http client. I expected to do something like:

    $guzzle = new GuzzleHttp\Client();
    $postcodeapi = app('PostcodeApi');
    $postcodeapi->setHttpClient($guzzle);
    

    This way I can mock the responses for the PostcodeApi. Same as you did with the openprovider package for laravel.

    Regards, Matthijs

    opened by matthijs 3
  • Class not found....

    Class not found....

    Hello,

    I'm using Laravel 5.8 and I have the following issue:

    ?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    class AddressController extends Controller
    {
    
        public function byPostcodeAndHouseNumber(Request $request)
        {
            $postCode21 = PostcodeApi::create('PostcodeApiNu')->findByPostcodeAndHouseNumber('1118CP', '202');
            return response()->json([
                'data' => $postCode21
            ]);
        }
    }
    
    Results in the following error:
    
    Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Http\Controllers\PostcodeApi' not found in file /app/Http/Controllers/AddressController.php on line 12
    Stack trace:
      1. Symfony\Component\Debug\Exception\FatalThrowableError->() /app/Http/Controllers/AddressController.php:12
    

    I like to know what I need to change

    Thanks, Roy

    opened by roydekleijn 2
  • "Undefined offset: 0"

    Laravel 5.5

    When I make a call with the following address:

    $address = PostcodeApi::create('PostcodeNL')->findByPostcodeAndHouseNumber($request->zipcode, $request->housenumber);

    I get this error. Any ideas?

    
    {message: "Undefined offset: 0", exception: "ErrorException",…}
    exception: "ErrorException"
    file: "C:\Projects\nspctr\vendor\guzzlehttp\guzzle\src\Client.php"
    line: 348
    message: "Undefined offset: 0"
    [{file: "C:\Projects\nspctr\vendor\guzzlehttp\guzzle\src\Client.php", line: 348,…},…]
    
    opened by bakkertjebrood 2
  • Allow laravel 9.x (And small readme fix)

    Allow laravel 9.x (And small readme fix)

    Tested this on a clean install of Laravel 9 with the PostcodeApiNu provider. Didn't have keys for the other ones but it Should be fine :)

    Also noticed a small variable mistake in the Readme example.

    opened by Koozza 1
  • Added 2 Providers for Germany

    Added 2 Providers for Germany

    Two providers have been added to find places for postal codes. They are Zippopotam.us and Geonames.org. Geonames however show a more reliable database

    opened by speedykhr 1
  • Allow fetching

    Allow fetching "postbus" addresses

    When fetching "Postbus" addresses they will be returned without lat/lng. This results in a TypeError as the setLatitude/setLongitude method expects a float. This PR will prevent that from happening when there is no lat/lng provided by Pro6PP.

    opened by arjanwestdorp 1
  • Unable to use provider

    Unable to use provider

    Hello,

    I've gotten this problem when calling functions. When calling functions like this:

    $address = \PostcodeApi::create('ApiPostcode')->findByPostcodeAndHouseNumber($request->code, $request->house);

    I get the following error: {message: "Unable to use the provider "ApiPostcode"",…} exception: "nickurt\PostcodeApi\Exception\InvalidArgumentException" file: "C:\wamp64\quartzline\vendor\nickurt\laravel-postcodeapi\src\ProviderFactory.php" line: 18 message: "Unable to use the provider "ApiPostcode"" trace: [{file: "C:\wamp64\quartzline\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php",…},…].

    Do you have any ideas to help me out?

    Thanks in advance!

    opened by Raymond-Wijkhuizen 1
  • Change PHP version to match Laravel 5.8 requirement

    Change PHP version to match Laravel 5.8 requirement

    The PHP version was upgraded in https://github.com/nickurt/laravel-postcodeapi/commit/5a481caec3be0194c48b4e0aaa0946a2dd46fbc4 to support Laravel 5.8, but L5.8 only requires PHP 7.1.3. Would it be possible to keep to 7.1.3 for now, to make upgrades easier (PHP 7.1 is still in security support; https://www.php.net/supported-versions.php )

    opened by barryvdh 1
  • Add house number addition to address from provider PostcodeApiNu

    Add house number addition to address from provider PostcodeApiNu

    Issue

    The nickurt\PostcodeApi\Entity\Address class that nickurt\postcodeapi\Providers\nl_NL\PostcodeApiNu returns does not contain the house number addition.

    Reproduce

    Execute the following function:

    $provider = \PostcodeApi::create('PostcodeApiNu');
    $provider->findByPostcodeAndHouseNumber('4817MK', '148EC6');
    

    This will result in:

    nickurt\PostcodeApi\Entity\Address {#1136
      #street: null
      #houseNo: null
      #town: null
      #municipality: null
      #province: null
      #latitude: null
      #longitude: null
    }
    

    The PostcodeApiNu API does include the house number addition as the addition field shown in the response from the PostcodeApiNu API:

    ...
    {
     "_embedded": {
        "addresses": [{
    			"purpose": "woonfunctie",
    			"postcode": "4817MK",
    			"addition": "C6",
    			"number": 148,
    			"year": 1980,
    ...
    
    opened by tomodutch 1
Owner
Nick
Nick
A toolkit for developing universal web interfaces with support for multiple CSS frameworks.

PHP UI Kit A toolkit for developing universal web interfaces with support for multiple CSS frameworks. Documentation Use cases One of the use cases is

Róbert Kelčák 6 Nov 8, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022
Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster.

Laravel Kickstart What is Laravel Kickstart? Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster. It com

Sam Rapaport 46 Oct 1, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 13 May 16, 2022
Laravel Sanctum support for Laravel Lighthouse

Lighthouse Sanctum Add Laravel Sanctum support to Lighthouse Requirements Installation Usage Login Logout Register Email Verification Forgot Password

Daniël de Wit 43 Dec 21, 2022
Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

Pham Thao 9 Nov 10, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
Laravel Jetstream is a beautifully designed application scaffolding for Laravel.

Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream provides the perfect starting point for your next Laravel application and includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management.

The Laravel Framework 3.5k Jan 8, 2023
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

Luca Patera 68 Dec 12, 2022
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Hussein Feras 52 Jul 17, 2022
A Laravel extension for using a laravel application on a multi domain setting

Laravel Multi Domain An extension for using Laravel in a multi domain setting Description This package allows a single Laravel installation to work wi

null 658 Jan 6, 2023
Example of using abrouter/abrouter-laravel-bridge in Laravel

ABRouter Laravel Example It's a example of using (ABRouter Laravel Client)[https://github.com/abrouter/abrouter-laravel-bridge] Set up locally First o

ABRouter 1 Oct 14, 2021
Laravel router extension to easily use Laravel's paginator without the query string

?? THIS PACKAGE HAS BEEN ABANDONED ?? We don't use this package anymore in our own projects and cannot justify the time needed to maintain it anymore.

Spatie 307 Sep 23, 2022
Laravel application project as Sheina Online Store backend to be built with Laravel and VueJS

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Boas Aditya Christian 1 Jan 11, 2022
Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model->myPoint = new Point(1,2); //lat

Max 340 Jan 6, 2023