Download the PHP package christianrey/laravel-addressable without Composer
On this page you can find all versions of the php package christianrey/laravel-addressable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download christianrey/laravel-addressable
More information about christianrey/laravel-addressable
Files in christianrey/laravel-addressable
Package laravel-addressable
Short Description Polymorphic postal addresses for Eloquent models, with purpose roles and an optional cost-aware Google enrichment layer.
License MIT
Informations about the package laravel-addressable
laravel-addressable
Polymorphic postal addresses for Eloquent models — purpose roles (main / shipping / tax), a hybrid international schema, local-first geographic resolution from open data, and an optional, cost-aware Google enrichment layer.
- 🏠 Addresses for any model — a polymorphic
Address+ anAddressabletrait, with main / shipping / tax roles enforced per owner. - 🗺️ Local-first geo — resolve country, region/province and postal code from your own tables (open GeoNames data). No API calls, no per-lookup cost.
- 💸 Optional Google enrichment — autocomplete, geocoding and address validation, opt-in per tier, with cost shown before any billable call and the API key kept server-side.
- 🧰 Headless — backend + artisan CLI. Bring your own frontend.
Requires: PHP 8.2+ · Laravel 11, 12 or 13.
Install
Publish the config if you want to tweak table names, tiers, pricing or routes:
Addresses & roles
Add the trait to any model:
Each owner holds at most one main, one shipping and one tax address; a single address may carry several roles at once. Assigning a role atomically demotes the previous holder. The schema is hybrid: typed, queryable columns (country_code, postal_code, locality, admin_area, latitude, longitude, …) plus a components JSON blob and a formatted_address.
Local-first geographic data
Resolve country, region/province and postal code from package-owned tables — no API calls, no per-lookup cost. Data comes from open GeoNames dumps (CC-BY 4.0), imported on demand.
It is not Spain-only
The engine works for any country GeoNames covers — you import the ones you need by ISO 3166-1 code:
Each --country=XX downloads and imports that country's regions and postal codes into your local tables (idempotent — safe to re-run). Nothing is bundled in the package; a fresh install starts with empty geo tables until you run this.
Resolving
Coverage & caveats (honest)
- Countries & regions exist for virtually every country. Postal codes are available for the ~100 countries GeoNames provides them for (most of Europe, North America, and many others) — coverage and granularity vary by country.
- Region names are stored generically as
admin1_name(top-level) andadmin2_name(second-level). Which level means "province" depends on the country. In Spain,admin1_nameis the autonomous community ("Galicia") andadmin2_nameis the province ("A Coruña"); elsewhere the meaningful level differs. The package stores both; you interpret them for your locale. - Postal → region linking uses the names from the postal data directly (not the GeoNames admin codes, which don't reliably match across countries), so the region/province is correct even where code-based joins fail.
Geographic data is provided by GeoNames under the Creative Commons Attribution 4.0 license.
Optional Google enrichment
Disabled by default (the null driver refuses enrichment calls). Enable the driver and only the tiers you want:
Enable the matching Google Cloud APIs: Places API (New) (autocomplete), Geocoding API (geocode), Address Validation API (validate).
A disabled tier (or a missing key) throws a typed exception — TierDisabledException, MissingApiKeyException, QuotaExceededException or MalformedResponseException — so failures are never silent. Set quota caps in Google Cloud Console to keep testing within the free tier.
CLI
Reference prices live in config/addressable.php under geocoding.pricing — editable, with an updated_at per SKU. They are a reference, not a live quote; always confirm against Google's pricing page.
Server-side proxy routes (optional)
Disabled by default. When enabled, your frontend calls these endpoints and the Google API key stays on the server — it is never sent to the browser.
| Method & path | Body | Returns |
|---|---|---|
POST /addressable/autocomplete |
{ "input": "…", "sessionToken"? } |
{ "suggestions": [{ "placeId", "text" }] } |
POST /addressable/geocode |
{ "address": "…" } |
{ "result": { …AddressData } \| null } |
POST /addressable/validate |
{ "line1": "…", "line2"?, "country_code"? } |
{ "complete": bool, "address": { …AddressData } } |
A disabled tier returns 409; quota 429; an unconfigured key 503; any upstream error 502 — all with generic bodies. Google's raw response is never forwarded to the client.
Testing
The Google driver is faked in tests — the suite never makes real network calls.
License
MIT. See LICENSE. Geographic data © GeoNames, CC-BY 4.0.
All versions of laravel-addressable with dependencies
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.16