Download the PHP package fndmiranda/simple-address without Composer
On this page you can find all versions of the php package fndmiranda/simple-address. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fndmiranda/simple-address
More information about fndmiranda/simple-address
Files in fndmiranda/simple-address
Package simple-address
Short Description Search address by postcode in multiple Api's and optionally get geocoding in Google Maps with the results.
License MIT
Informations about the package simple-address
Art of README
This article can also be read in Brazilian Portuguese.
Simple address from Laravel
This package simplifies the search for addresses by zip code in Api`s and the management of addresses in the database, you can also create your own adapters for api queries.
Installation
Usage
Publish the package configuration file with vendor:publish Artisan command:
The published configuration file address.php will be placed in your config directory.
Api`s of search
The list of Api's available is located in your config/address.php file in apis and you can remove or add new adapters as follows:
If you change force_priority in config/address.php to true the search order will always conform to the list of apis
adapters, by default this value is false for the order to be random.
With the search method on the facade of the Address the package will loop in the apis until finding the requested postcode as follows:
Geocoding
You can use the data returned by the search method to obtain the latitude and longitude of the address with the
geocoding method of the facade Address as follows:
Note, to use the geocoding feature you need to provide the Google Maps API key, add the ADDRESS_GOOGLE_MAPS_KEY
entry in your .env file as follows:
Database
This package comes with a complete database structure to store the searched addresses.
Note that a table for polymorphism will be created, which should be created with the type of column that will make the
relation the same that you use in your tables by setting the column_type in the config/address.php file and the
options are integer, bigInteger and uuid there then create the tables with migrate Artisan command:
Migration Customization
If you are not going to use SimpleAddress default migrations, you should call the Address::ignoreMigrations method in
the register method of your AppServiceProvider.
You may export the default migrations using vendor:publish Artisan command:
If you do not want to manage the addresses in the database and just want to query in api,
change the config/address.php file manager_address to false.
Saving in database
Example of integration of supplier model with address polymorphism.
You can then save the address to a supplier by using the search and geocoding methods of the facade Address
as in the following example:
Or in your controller
Request body example
Creating your custom adapter
You can create your own custom adapter to query an API that is not in the list, you may generate an
adapter of the simple-address:make Artisan command:
This command will generate a adapter at app/SimpleAddress/Adapters/YourApiAdapter.php.
The file will contain the empty search andprepare methods, so you can adapt them by following the file
structure as in the following example:
Add your adapter to the apis list in the config/address.php file as follows:
If you create a new Api adapter, I would appreciate if you open a pull request by adding your adapter and mapping
it in the apis list in config/address.php of the package.
Method search
The search method sends the request to an endpoint to query a postcode and uses the prepare method to transform the
obtained data into a standard array and returns them or returns false if the postcode is not found or if api does
not respond so that it automatically query on the next api adapter.
Method prepare
The prepare method will transform the data returned by an api into a standard array with the
keys postcode, address, neighborhood, city and state.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.