aw codes icon logo
Docs Hub

Search across every project.

Postal Codes Switch project

This is a package to easily install and use postal codes in your Laravel application from GeoNames.org

1.x Current

On this page

Postal Codes

Postal Codes gives a Laravel application a local postal_codes table populated from GeoNames country data, along with an Eloquent model to query it.

Rather than calling a geocoding API at request time, you seed the data once with an Artisan command and query it like any other table. Lookups are ordinary database queries, so they work offline, cost nothing per call, and can be joined against your own records.

What you get

Installing the package adds three things to your application:

  • A postal_codes table, created by a migration the package publishes.
  • An Awcodes\PostalCodes\Models\PostalCode Eloquent model.
  • A postal-codes:seed command that downloads and imports a country's data.

Each row carries the postal code itself plus its place name, administrative divisions, and latitude and longitude. See Usage for the full column reference.

Where the data comes from

All data comes from the GeoNames postal code export at download.geonames.org/export/zip, which publishes one archive per country.

The seed command downloads the archive for the country you name, imports it, and cleans up after itself. Nothing is bundled with the package, so the download directory is also the definitive list of which countries are available.

Next steps

Start with Installation, then seed your first country in Usage.