novasemantics/nepal-locations-laravel
Composer 安装命令:
composer require novasemantics/nepal-locations-laravel
包简介
A Laravel-friendly PHP package that provides structured data for Nepal's administrative divisions, including provinces, districts and cities. Easily integrate location-based hierarchies into your Laravel apps.
README 文档
README
NepalLocations is a Laravel package providing Nepal’s geographical data — provinces, districts, cities, and their hierarchical relationships. It offers a structured way to access and manipulate this data using Laravel's powerful query builder API.
Features
- Eloquent models:
Province,District,City - Collision free table names with configurable prefixes
- Enum support for
CityType - One-command import with:
- Full or partial import options
- Smart update/merge of existing data
- Selective field overriding
- JSON-driven immutable source data
- Useful relationships:
Province → Districts & CitiesDistrict → Cities
Installation
Require the package via Composer:
composer require novasemantics/nepal-locations-laravel
You can install the package's assets and configuration file using the following artisan command:
php artisan nepal-locations-laravel:install
- The installation command will publish the package's configuration file to
config/nepal-locations-laravel.php. - It will also publish the migration files to
database/migrations/. - Then you will be asked to run the migrations to create the necessary database tables.
- Finally, you will be prompted to run the import command to populate the database with initial data.
How to Get Updated Data
The package is maintained with the latest geographical data of Nepal. To get the most recent data, you can update the package using Composer:
composer update novasemantics/nepal-locations-laravel
Then you can manually run the import command to refresh the data in your database:
php artisan import:geo-data
Fresh Import option will be provided to overwrite existing data with the latest from the package, if you have been using the data in foreign keys or relationships, you can choose to update only the fields you need without affecting the existing relationships. As the ID's for geo tables are immutable, you can safely update without worrying about breaking changes.
⚙️ Models Overview
Province
The Province model represents Nepal's administrative provinces. It contains information about the province's name,
area, population, and its districts.
District
The District model represents the districts within a province. It includes details such as the district's name, area,
population, and the province it belongs to.
City
The City model represents cities within a district. It includes the city's name, type (e.g., Metropolitan,
Sub-Metropolitan), area, population, and the district it belongs to.
Data Structure
| Field | Type | Description | Models |
|---|---|---|---|
id |
Integer | Unique identifier | All |
name |
String | English name of the location | All |
name_np |
String | Nepali name of the location | All |
lat |
Float | Latitude | All |
lng |
Float | Longitude | All |
area |
Float | Area in square kilometers | All |
population |
Integer | Population count | All |
type |
Enum | Type of city (e.g., Metropolitan, Sub-Metropolitan) | City |
wards |
Integer | Number of administrative wards | City |
province_id |
Integer | Foreign key to Province | District, City |
district_id |
Integer | Foreign key to District | City |
additional_fields |
Array | Additional fields like website,phone | All |
📥 Importing Geo Data
Use the following artisan command:
php artisan import:geo-data
What it does:
- Interactive CLI to:
- Choose which data types to import (
provinces,districts,cities) - Perform fresh import or update mode
- Select specific fields to override on update
- Confirm before execution
- Choose which data types to import (
Example:
php artisan import:geo-data
You’ll be prompted with interactive options for a safe and flexible import experience.
💡 Example Usage
Get all districts of Province ID 3
use NovaSemantics\NepalLocations\Models\Province; $province = Province::find(3); $districts = $province->districts; // Or directly get cities of the province $cities = $province->cities;
Get all cities of a district
use NovaSemantics\NepalLocations\Models\District; $district = District::find(12); $cities = $district->cities;
Get all metropolitan cities
use NovaSemantics\NepalLocations\Enums\CityType; use NovaSemantics\NepalLocations\Models\City; $cities = City::where('type', CityType::Metropolitan)->get();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
novasemantics/nepal-locations-laravel 适用场景与选型建议
novasemantics/nepal-locations-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「geodata」 「nepal」 「novasemantics」 「nepali-data-api」 「nepali-data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 novasemantics/nepal-locations-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 novasemantics/nepal-locations-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 novasemantics/nepal-locations-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package will get the full address information based on the zipcode and house number. Currently online dutch addresses are supported.
US zipcode static database.
Laravel Geocode by address library
A frontend maps module.
API to get all countries and all cities in a country.
Laravel package for fetching and managing gold and silver prices with Filament integration
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-30