Get the data from the most recondite place with 'Atlas'

Maintainers

Package info

github.com/RaiolaNetworks/Atlas

Issues

pkg:composer/raiolanetworks/atlas

Transparency log

Statistics

Installs: 648

Dependents: 0

Suggesters: 0

Stars: 3

3.0.2 2026-07-16 09:53 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

With 'Atlas' you will be able to create new tables in the database and fill them with information about countries, states, cities, timezones and more.

Requirements

  • PHP 8.3+
  • Laravel 12+

Get to know us

Installation

Install the package via Composer:

composer require raiolanetworks/atlas

Optionally publish the config file to customise table names or toggle entities:

php artisan vendor:publish --tag="atlas-config"

Run the migrations and seed the database:

php artisan atlas:install

The command will migrate the tables for every entity enabled in config('atlas.entities') (all enabled by default) and let you choose which seeders to run. The process may take a few minutes due to the large number of cities.

To re-seed the data after a package upgrade:

php artisan atlas:update

Other publishable resources

php artisan vendor:publish --tag="atlas-translations"
php artisan vendor:publish --tag="atlas-jsons"        # JSON data files (for overriding)

Note: Migrations are auto-loaded by the package. Do not publish them with --tag="atlas-migrations" unless you have a specific reason — published copies will cause "table already exists" errors.

Usage

Internally, the package works with Laravel models, which allows you to work with this model as if they were models of your own project.

For example, if you want to get all the countries in Africa:

use Raiolanetworks\Atlas\Models\Country;

class MyClass
{
	public function getAllAfricaCountries(): Collection
	{
		return Country::where('region_name', 'Africa')
			->orderBy('name')
			->get();
	}
}

State hierarchy

States support multi-level administrative divisions. Use admin_level to distinguish between primary regions (level 1) and subdivisions (level 2+):

use Raiolanetworks\Atlas\Models\State;

// Get only top-level divisions (e.g., Autonomous Communities in Spain)
State::where('country_code', 'ES')->topLevel()->get();

// Get subdivisions of a specific state
$catalonia = State::where('state_code', 'CT')->first();
$catalonia->children; // Provinces: Barcelona, Girona, Lleida, Tarragona

// Navigate up the hierarchy
$barcelona = State::where('name', 'Barcelona')->first();
$barcelona->parent; // Cataluña

Scope and limitations

The hierarchy support is intentionally uneven — read this before relying on it:

  • admin_level, topLevel() and adminLevel() work for every country. They classify each division as primary (level 1) or subdivision (level 2), which is enough to keep dropdowns to first-level divisions.
  • parent() / children() only return data for the countries where parent_id is populated (340 divisions): Spain, France, Italy, Belgium, Ireland, Sri Lanka, Fiji, Bosnia & Herzegovina, Equatorial Guinea and Saint Kitts & Nevis. For any other country parent_id is null, so parent() returns null and children() returns an empty collection.
  • topLevel() does not guarantee unique names within a country. A few countries have two co-equal first-level divisions that share a name — e.g. Minsk oblast + Minsk city (BY), Almaty region + Almaty city (KZ), Moscow oblast + Moscow city (RU), Zagreb county + Zagreb city (HR), cities vs counties in Taiwan, state cities vs municipalities in Latvia. These are genuinely different places (not parent/child), so both correctly stay at level 1. Disambiguate them by type or state_code:
State::where('country_code', 'BY')->topLevel()->get()
    ->map(fn (State $s) => "{$s->name} ({$s->type})"); // "Minsk (oblast)", "Minsk (city)"

Upgrading

If you are upgrading between major versions, please see UPGRADE.md for the list of breaking changes and migration steps.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.