blax-software/laravel-addresses
Composer 安装命令:
composer require blax-software/laravel-addresses
包简介
Universal Laravel address management system — from rural coordinates to skyscraper rooms, worldwide.
README 文档
README
Laravel Addresses
Universal Laravel address management — from rural GPS coordinates to specific rooms inside skyscrapers, worldwide.
Overview
This package provides a complete address management system for Laravel applications built on a three-layer architecture:
Address → The physical place (street, city, coordinates …)
└── AddressLink → Connects an address to a model with a purpose (User's "Office")
└── AddressAssignment → References a link from another context (Job's "pickup")
Example: A user has an office address. A job references that office as its pickup location — without duplicating the address data.
Features
- 15 address fields — street-level to room-level precision, with GPS coordinates (WGS-84) and altitude
- Polymorphic links — attach addresses to any Eloquent model
- 17 built-in link types — Home, Office, Shipping, Billing, Warehouse and more
- Address assignments — reference someone else's address in another context
- Temporal validity —
active_from/active_untilon every link - AddressService — distance calculations (Haversine), proximity queries, duplicate detection, coordinate conversion
- Auto-geocoding — saves call Nominatim (OpenStreetMap) for lat/lon, serialized by a Cache lock and paced at 1 req/sec
- Fully configurable — custom model classes, table names, default link type
- Soft deletes on addresses, cascade deletes on links and assignments
Requirements
- PHP 8.1+
- Laravel 9, 10, 11 or 12
blax-software/laravel-workkit(installed automatically)
Installation
composer require blax-software/laravel-addresses
Publish and run the migrations:
php artisan vendor:publish --tag="addresses-migrations"
php artisan migrate
Optionally publish the config:
php artisan vendor:publish --tag="addresses-config"
Quick Start
1. Add the trait to your model
use Blax\Addresses\Traits\HasAddresses; class User extends Model { use HasAddresses; }
2. Create and attach an address
use Blax\Addresses\Enums\AddressLinkType; $link = $user->addAddress([ 'street' => '350 Fifth Avenue', 'city' => 'New York', 'state' => 'NY', 'postal_code' => '10118', 'country_code' => 'US', 'latitude' => 40.748817, 'longitude' => -73.985428, ], AddressLinkType::Office);
3. Query addresses
$user->addresses; // all addresses $user->addressesOfType(AddressLinkType::Office); // only offices $user->primaryAddress(); // primary across all types $user->activeAddressLinks(); // only currently active links
4. Assign an address to another model
use Blax\Addresses\Traits\HasAddressAssignments; class Job extends Model { use HasAddressAssignments; } $job->assignAddressLink($link, 'pickup'); $job->assignedAddressForRole('pickup'); // → the Address model
5. Automatic geocoding (opt-in)
Set ADDRESSES_GEOCODING_ENABLED=true to have an observer ask Nominatim
(OpenStreetMap) for latitude / longitude after every save. Calls are
serialized cluster-wide through a Cache::lock and paced at 1 req/sec
to honour the OSMF usage policy. Off by default so an upgrade
doesn't surprise existing apps with new outbound HTTP traffic.
# .env ADDRESSES_GEOCODING_ENABLED=true # OSMF policy: identify your app — generic UAs get blocked. ADDRESSES_GEOCODING_USER_AGENT="my-app (https://example.com)" ADDRESSES_GEOCODING_EMAIL="ops@example.com"
$address = Address::create([ 'street' => 'Stephansplatz 1', 'postal_code' => '1010', 'city' => 'Vienna', 'country_code' => 'AT', ]); // Observer has filled these in by the time create() returns. $address->refresh(); $address->latitude; // 48.2082… $address->longitude; // 16.3738…
Tunable knobs (see config/addresses.php →
geocoding):
enabled— master switch (env:ADDRESSES_GEOCODING_ENABLED)driver— onlynominatimships out of the box, but you can rebind theGeocodercontract to plug in Google Maps / Mapbox / Mapquest / a self-hosted Nominatimupdate_only_when_missing— leave manually-entered coordinates alonemin_interval_seconds— global ceiling on outbound traffic (default1.0, matches Nominatim's published policy)lock_wait_seconds,lock_ttl_seconds— Cache lock parametersaccept_language— Nominatim'sdisplay_namelocalizationdrivers.nominatim.user_agent/email— required by Nominatim for attribution; set both in production
For tests / imports, disable per-environment with
ADDRESSES_GEOCODING_ENABLED=false (or
config()->set('addresses.geocoding.enabled', false) inside a TestCase
hook).
6. Use the AddressService
// Via helper $distance = address()->distanceBetween($addressA, $addressB); // km // Nearby addresses within 10 km $nearby = address()->nearby(48.2082, 16.3738, 10); // Format for display echo address()->formatMultiline($address);
Documentation
| Guide | Description |
|---|---|
| Installation & Configuration | Setup, publishing, config options |
| Core Concepts | The three-layer architecture explained |
| HasAddresses Trait | Full API for address-owning models |
| HasAddressAssignments Trait | Full API for address-consuming models |
| AddressService | Distance, proximity, formatting, conversion |
| Geocoding | Auto lat/lon via Nominatim, cache lock, rate limit |
| AddressLinkType Enum | All 17 built-in types with descriptions |
| Customization | Extending models, custom tables, overriding defaults |
Testing
composer test
License
MIT
Star History
blax-software/laravel-addresses 适用场景与选型建议
blax-software/laravel-addresses 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「address」 「laravel」 「location」 「coordinates」 「addresses」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blax-software/laravel-addresses 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blax-software/laravel-addresses 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blax-software/laravel-addresses 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Module adding custom shipping attribute for what3words address
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-17