Download the PHP package hasyirin/laravel-address without Composer
On this page you can find all versions of the php package hasyirin/laravel-address. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hasyirin/laravel-address
More information about hasyirin/laravel-address
Files in hasyirin/laravel-address
Package laravel-address
Short Description Polymorphic address management for Laravel with hierarchical geographical data and built-in Malaysian dataset.
License MIT
Homepage https://github.com/hasyirin/laravel-address
Informations about the package laravel-address
Laravel Address
A Laravel package for managing addresses with polymorphic relationships and hierarchical geographical data (countries, states, districts, subdistricts, and post offices).
Comes with built-in geographical data for Malaysia and a seeder command to populate reference tables.
Requirements
- PHP 8.4+
- Laravel 12 or 13
Installation
Install the package via Composer:
Publish and run the migrations:
Optionally publish the config file:
Seeding Geographical Data
Seed countries, states, districts, subdistricts, and post offices:
The command loads data from the package's data/ directory. To use your own data, place JSON files in your application's base_path('data') directory following the same structure.
Usage
Preparing Your Model
Add the InteractsWithAddresses trait to any model that should have addresses:
Creating Addresses
Using the Factory
The Address model includes a factory for testing:
Retrieving Addresses
Querying by Type
The ofType scope accepts a string, array, or enum:
Formatting
HTML Rendering
Copying an Address
Create an unsaved copy of an address (without the polymorphic relationship or type):
Locality
Designate a "local" country, state, and district by setting their codes in config/address.php:
Resolve them anywhere via the static helper — it enforces the parent chain, so a state only counts as local if its country also matches the configured code:
If any level is null in the config, the corresponding local() returns null.
Compose with the local() query scope:
The result is memoized per request via cache()->memo(). saved and deleted listeners on each model cascade-clear caches down the chain (Country save clears State and District caches too). For manual invalidation:
Configuration
Data Structure
The package uses a hierarchical location model:
Each Address belongs to a Country, State, and optionally a PostOffice, and is polymorphically attached to any model via the addressable morph relationship.
Models
| Model | Key Fields |
|---|---|
Country |
code (ISO 3166-1 alpha-3), alpha_2, name |
State |
code, name, belongs to Country |
District |
code, name, belongs to State |
Subdistrict |
code, name, belongs to District |
PostOffice |
name, postcodes (JSON array), belongs to State |
Address |
type, line_1-line_3, postcode, latitude, longitude, properties (JSON) |
All models use soft deletes.
Extending Models
To use your own model classes, extend the package models and update the config:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Hasyirin Fakhriy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-address with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^12.0||^13.0