PHPackages                             ardyn/zipcode - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ardyn/zipcode

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ardyn/zipcode
=============

A zip code database for your projects.

9702[1 issues](https://github.com/ardyn/zipcode/issues)PHP

Since Feb 20Pushed 11y ago3 watchersCompare

[ Source](https://github.com/ardyn/zipcode)[ Packagist](https://packagist.org/packages/ardyn/zipcode)[ RSS](/packages/ardyn-zipcode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Zip Code Database
=================

[](#zip-code-database)

Use this package to convert a zip code into geographic coordinates, calculate distances between two zip codes, find the nearest zip code to a latitude and longitude point, and return a list of zip codes within a radius of a zip code.

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

[](#installation)

Install via composer, publish configuration files, setup the database using the new artisan commands, register service providers and aliases.

### Composer

[](#composer)

Edit your `composer.json` file:

```
"require": {
  "ardyn/zipcode": "0.5"
}
```

Run `composer update`.

### Publish Configuration Files

[](#publish-configuration-files)

If you want to change default configuration settings, run `php artisan config:publish ardyn/zipcode`, then modify the contents of `app/config/packages/ardyn/zipcode/config.php`.

### Integrate with Laravel

[](#integrate-with-laravel)

Add the following to the `providers` array in your `app/config.php` file:

```
'Ardyn\Zipcode\ZipCodeServiceProvider'
```

Add the alias in `aliases` array:

```
'Zipcode' => 'Ardyn\Zipcode\Facades\ZipCode'
```

### Database Setup

[](#database-setup)

To create the migrations, run `artisan zipcode:migrate source` where `source` is a CSV file of the zip code data with column headers. This will create the migration using data from the `config.php` file. You may supply additional columns by including them with the `--columns` option and deliminating each column by a comma \[,\]. The column names must match the headers in your zip code data source file. Migrations will be moved to the migrations directory, as set in the `config.php` file.

After the migrations have been published, you may use `artisan migrate` to run the migrations.

To seed the database, call `artisan zipcode:seed source` where source is the same CSV file used for the migration. By default, only the zip\_code, latitude, and longitude columns will be seeded. To include more columns, use the `columns` option. As with the migration, the `columns` must exist in the headers of the data source file.

Some methods are cached forever. You may want to clear your cache after updating the database.

Usage
-----

[](#usage)

Usage is incredibly simple. Just call `Zipcode::find($zipCode)` to return a ZipCode model.

Examples:

```
// Finds the zip code and returns the ZipCodeEngine class
$zipCode = Zipcode::find('90210');

// Return a property of the zip code record
// These three methods are agnostic of your database column names
$zipCode->zipCode();
$zipCode->latitude();
$zipCode->longitude();

// Access any other column using its name
$zipCode->my_column;

// Calculate distance between two zip codes
Zipcode::distance($zipCode, '84102', "miles");

// Return all zip codes within $outerRadius and $innerRadius
Zipcode::radiusSearch($zip1, $zip2, $outerRadius, $innerRadius, "miles");

// Find nearest zip code
Zipcode::nearest($latitude, $longitude);
```

### Units

[](#units)

When calling the distance method or the radiusSearch method, you can supply a 'unit' parameter of "miles", "feet", "kilometers", "meters", "radians", or "degrees".

Extending the Package
---------------------

[](#extending-the-package)

You may over-ride the default Model by editing the `config.php` file to use your own model, which must implement `ardyn\Zipcode\Models\ZipCodeModelInterface`. The repository may also be extended.

To change the model primaryKey, or table, you can just edit the `config.php` file as the provided ZipCodeRepository class will set those fields on the model.

Zip Code Data Source
--------------------

[](#zip-code-data-source)

The provided zip code data in `/src/sample.csv` is only for demonstration purposes only! To obtain a complete zip code list, visit \[\] for a free database or purchase from \[\] for a database with more accurate WGS84 coordiantes.

TODO
----

[](#todo)

- Refactor this shit!
- Semantic versioning!
- Unit test the ZipCodeRepository
- Unit test the artisan commands
- Better documentation!
- Find should return a StdClass instead of an Eloquent Model

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbc7cf61fec96797714f9d0aa35677ad491fe8f3d1314530bcf0e1b011aa9650?d=identicon)[ardyn](/maintainers/ardyn)

---

Top Contributors

[![ardyn](https://avatars.githubusercontent.com/u/7873022?v=4)](https://github.com/ardyn "ardyn (6 commits)")

### Embed Badge

![Health badge](/badges/ardyn-zipcode/health.svg)

```
[![Health](https://phpackages.com/badges/ardyn-zipcode/health.svg)](https://phpackages.com/packages/ardyn-zipcode)
```

###  Alternatives

[t4web/composer-lock-parser

OOP reader of composer.lock file.

20185.2k7](/packages/t4web-composer-lock-parser)[albertborsos/yii2-gdpr-cookie-consent

GDPR compatible Cookie Consent widget allows the user to choose which kind of cookies they want to accept.

1124.3k1](/packages/albertborsos-yii2-gdpr-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
