nickurt / laravel-postcodeapi Goto Github PK
View Code? Open in Web Editor NEWUniversal PostcodeApi for Laravel 10.x/11.x
License: MIT License
Universal PostcodeApi for Laravel 10.x/11.x
License: MIT License
Your package currently does not work with Laravel 5.2 because it Laravel 5.2 uses Guzzle 6.* and your package requires 5.*
The url is changed, the correct one is https://api.pdok.nl/bzk/locatieserver/search/v3_1/free
This can be verified by opening the old url in a webbrowser
I've made a patch, but removed the fork before it was patched c773aae
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!
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.
It'd be awesome to allow aliasing providers. This would make it super easy to use a sandbox that shares a class, but runs using a different endpoint and API key
For example, let's look at postcodeapi.nu, which has a live environment (v3) on https://api.postcodeapi.nu/v3/lookup
and a sandbox under https://sandbox.postcodeapi.nu/v3/lookup
By allowing aliases, you could have this config:
<?php
return [
'postcodeapi-nu' => [
'alias' => \nickurt\PostcodeApi\Providers\nl_NL\PostcodeApiNu::class,
'url' => 'https://api.postcodeapi.nu/v3/lookup/%s/%s',
'key' => 'key',
],
'postcodeapi-nu-sandbox' => [
'alias' => \nickurt\PostcodeApi\Providers\nl_NL\PostcodeApiNu::class,
'url' => 'https://sandbox.postcodeapi.nu/v3/lookup/%s/%s',
'key' => 'sandbox',
],
];
You'd probably only have to make a small change, and include some tests.
/** @var Provider $class */
- if (class_exists($providerClass = 'nickurt\\PostcodeApi\\Providers\\' . $config['code'] . '\\' . $provider)) {
+ $providerClass = $config['alias'] ?? "nickurt\\PostcodeApi\\Providers\\{$config['code']}\\{$provider}")
+ if (class_exists($providerClass)) {
$class = (new $providerClass);
$class->setApiKey($config['key']);
Sometimes it is required to have a correct extension number for a housenumber to return a existing address.
This packages requires PHP 7.2 minimum, isn't it too high?
When running in dev, I noticed no problems with the autoloading, but when switching composer to use --classmap-authoritative
, some classes aren't available.
I think this has to do with incorrect namespace capitalisation, as seen here:
Fix the namespaces
Maybe run phpunit
again after composer dump-autoload --classmap-authoritative
, to check if all classes remain available.
I'll get to work on a PR, shouldn't be too long.
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,…},…]
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
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
Hi,
Laravel autodiscover is not working with 1.1.
Could you tag master with a new version, so we can use Autodiscovery?
Thanks :)
The nickurt\PostcodeApi\Entity\Address
class that nickurt\postcodeapi\Providers\nl_NL\PostcodeApiNu
returns does not contain the house number addition.
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,
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.