PHPackages                             dillingham/locality - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. dillingham/locality

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

dillingham/locality
===================

Automatic Address Normalization in Laravel

0.0.8(4y ago)211[1 issues](https://github.com/dillingham/locality/issues)MITPHPPHP ^8.0

Since Sep 28Pushed 4y agoCompare

[ Source](https://github.com/dillingham/locality)[ Packagist](https://packagist.org/packages/dillingham/locality)[ Docs](https://github.com/dillingham/locality)[ GitHub Sponsors](https://github.com/dillingham)[ RSS](/packages/dillingham-locality/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (8)Versions (9)Used By (0)

Locality
========

[](#locality)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c19bab963fd98e5b409567768be4a81bd7f0770656356e887ee1ac6855de07fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696c6c696e6768616d2f6c6f63616c6974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dillingham/locality)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dccda957a9baa52637f7802b41a1ffdd203afa503a750415fd6f81e3d354babc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f64696c6c696e6768616d2f6c6f63616c6974792f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/dillingham/locality/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e814a4ab51966e2a2109efbab9a1743e8e9b4cc02aa112abfeaffbb241999534/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f64696c6c696e6768616d2f6c6f63616c6974792f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/dillingham/locality/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8f3074024f4bd2fd61bc2ddedf646cc15a719dd9b056d4cc5a861bf4468fef38/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696c6c696e6768616d2f6c6f63616c6974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dillingham/locality)

---

A Laravel package that automatically normalizes address data. Instead of storing city state &amp; zipcodes repeatedly, create tables and reference the foreign key. This package accepts the string representation, checks if it exists or creates it and adds the relationship. This package also provides accessors to make it feel as though you aren't even normalizing.

---

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require dillingham/locality
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Dillingham\Locality\LocalityServiceProvider" --tag="locality-config"
```

Add the following columns to your model's migration:

```
$table->addAddress();
```

Which is just a shorthand for adding these columns:

columnnullableindexeddescriptionaddress\_1yesnostreet and building numberaddress\_2yesnooptional unit numberadmin\_level\_3\_idyesyesthe neighborhood political regionadmin\_level\_2\_idnoyesthe city political regionadmin\_level\_1\_idnoyesthe state political regionpostal\_code\_idnoyesthe postal foreign keycountry\_idyesnothe country foreign keyformatted\_addressnonostatic address without queriesThe 5 tables will be migrated:

```
php artisan migrate

```

Then add the `HasAddress` trait:

```
