PHPackages                             fndmiranda/simple-address - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. fndmiranda/simple-address

ActiveLibrary

fndmiranda/simple-address
=========================

Search address by postcode in multiple Api's and optionally get geocoding in Google Maps with the results.

1.2.2(5y ago)762866MITPHPPHP &gt;=7.0.0

Since May 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/fndmiranda/simple-address)[ Packagist](https://packagist.org/packages/fndmiranda/simple-address)[ RSS](/packages/fndmiranda-simple-address/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (10)Used By (0)

Art of README
=============

[](#art-of-readme)

*This article can also be read in [Brazilian Portuguese](README-pt-BR.md).*

Simple address from Laravel
---------------------------

[](#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

[](#installation)

```
composer require fndmiranda/simple-address

```

### Usage

[](#usage)

Publish the package configuration file with `vendor:publish` Artisan command:

```
php artisan vendor:publish --tag=simple-address-config

```

The published configuration file `address.php` will be placed in your `config` directory.

Api`s of search
---------------

[](#apis-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:

```
'apis' => [
    Fndmiranda\SimpleAddress\Adapters\ViaCepAdapter::class,
    Fndmiranda\SimpleAddress\Adapters\PostmonAdapter::class,
    Fndmiranda\SimpleAddress\Adapters\WidenetAdapter::class,
],
```

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:

```
$address = Address::search(38017170);
```

Geocoding
---------

[](#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:

```
$address = Address::search(38017170);

$geocode = Address::geocoding($address);
```

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:

```
ADDRESS_GOOGLE_MAPS_KEY=YourMapsKey
```

Database
--------

[](#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:

```
php artisan migrate

```

### Migration Customization

[](#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:

```
php artisan vendor:publish --tag=simple-address-migrations

```

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

[](#saving-in-database)

Example of integration of supplier model with address polymorphism.

```
