raiolanetworks/atlas
Composer 安装命令:
composer require raiolanetworks/atlas
包简介
Get the data from the most recondite place with 'Atlas'
README 文档
README
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()andadminLevel()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 whereparent_idis populated (340 divisions): Spain, France, Italy, Belgium, Ireland, Sri Lanka, Fiji, Bosnia & Herzegovina, Equatorial Guinea and Saint Kitts & Nevis. For any other countryparent_idisnull, soparent()returnsnullandchildren()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 bytypeorstate_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 from 1.x, please see UPGRADE.md for a 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.
raiolanetworks/atlas 适用场景与选型建议
raiolanetworks/atlas 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 645 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「countries」 「country」 「city」 「cities」 「atlas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 raiolanetworks/atlas 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 raiolanetworks/atlas 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 raiolanetworks/atlas 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Sun Country is the package that helps you to get the country name & dialing code by the country ISO 3166-1 Alpha-2 code.
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
Country select field type.
Country Flag Emoji for PHP
Check for holidays - localeaware
统计信息
- 总下载量: 645
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-19