Download the PHP package masterix21/laravel-addressable without Composer

On this page you can find all versions of the php package masterix21/laravel-addressable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-addressable

Make your Eloquent models addressable

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Attach any number of addresses to any Eloquent model through a polymorphic relation. Built on top of matanyadaev/laravel-eloquent-spatial, it natively supports geospatial coordinates and distance queries — perfect for billing, shipping or any location-aware use case.

Features

Requirements

Support us

If you like my work, you can sponsor me.

Installation

Install the package via Composer:

Publish and run the migrations:

Optionally publish the config file:

Upgrading from 2.1.x

Publish and run the additional meta column migration:

Upgrading from 2.2.x

Spatial index (optional but recommended). Publish and run the spatial index migration to make coordinates indexed for fast distance queries:

The migration:

primaryAddress is now a relation. It used to be a method returning ?Address. It now returns a MorphOne relation, which means:

Configuration

The published config/addressable.php file exposes:

Usage

Attach addresses to a model

HasAddresses is the generic trait. For billing or shipping flows, use the dedicated traits (they can be combined):

When the parent model is hard-deleted, its addresses are automatically removed. If the parent uses SoftDeletes, addresses survive soft-delete and are removed only on forceDelete().

Create addresses

Address fields

Field Type Notes
label string Optional tag (e.g. "Home", "Office")
is_primary bool Toggled via markPrimary()
is_billing bool Set automatically by the helper
is_shipping bool Set automatically by the helper
street_address1 string
street_address2 string
zip string
city string
state string
country string ISO alpha-2/3 (max 4 chars)
coordinates Point Cast to a spatial Point object
meta array JSON column for arbitrary data

Mark an address as primary

markPrimary() ensures a single primary address per type, scoped to the same parent model. It is wrapped in a transaction and unmarks any other primary address of the same kind.

Events

Every primary toggle dispatches dedicated events (each carrying the Address instance):

Action Generic event Billing event Shipping event
markPrimary() AddressPrimaryMarked BillingAddressPrimaryMarked ShippingAddressPrimaryMarked
unmarkPrimary() AddressPrimaryUnmarked BillingAddressPrimaryUnmarked ShippingAddressPrimaryUnmarked

All events live in Masterix21\Addressable\Events. Billing/shipping variants fire only when the respective flag is set on the address.

Query scopes

Inverse relationship

Metadata

Every address has a JSON meta column for extra data without touching the schema:

Display address

The display_address accessor returns a readable representation:

Customize the format in config/addressable.php:

Geospatial features

Store coordinates

Filter by distance

Use the withinRadius scope for the common case of "addresses within N meters of a point":

For custom comparisons (<, >=, etc.) drop down to the underlying spatial scope:

Add distance as a column

addDistanceTo() appends the distance from a given point (always in meters) as an extra column. Divide by 1000 for kilometers, by 1609.344 for miles.

Order by distance and find nearest

orderByDistance() sorts addresses by distance from a point without adding any column. nearest() is the high-level helper for "give me the N closest addresses": it adds the distance column, orders ascending and optionally applies a limit.

Geocoding

Geocoding turns a textual address into coordinates, and reverse geocoding does the opposite. Drivers are tried in order (FIFO): the first one returning a result wins, so a failing driver falls back to the next.

Two keyless drivers ship enabled by default: Nominatim (OpenStreetMap) and Photon (Komoot).

Google driver

A Google driver is provided as well. It is commented out in config/addressable.php — uncomment its entry and set GOOGLE_GEOCODER_KEY:

Drivers are tried in array order, so placing google first makes it the primary driver with Nominatim and Photon as fallbacks. The Google driver uses the Geocoding API for both forward and reverse geocoding, and treats any response whose status is not OK as a miss (falling through to the next driver).

Geocode an address

Reverse geocode coordinates

Both methods emit the AddressGeocoded event on success.

Automatic geocoding

Enable addressable.geocoding.auto (or ADDRESSABLE_GEOCODER_AUTO=true) to geocode addresses saved without coordinates automatically:

When enabled, the addressable.geocoding.job is dispatched for every address saved without coordinates. The default GeocodeAddressJob job runs synchronously. To geocode on a queue instead — recommended for web requests, so the geocoder HTTP call doesn't block the response — extend the job and point the config at your subclass:

Note: Nominatim and Photon are free public services with a usage policy (Nominatim limits to ~1 request/second). For high volume, use Google or a self-hosted instance, and throttle bulk geocoding on your side.

Custom drivers

Implement Masterix21\Addressable\Geocoding\Contracts\Geocoder and add it to addressable.geocoding.drivers. Each driver receives its own config block (plus the shared srid and user_agent).

AI guidelines (Laravel Boost)

This package ships Laravel Boost guidelines. If your app uses Boost, run php artisan boost:install (or php artisan boost:update --discover) and select laravel-addressable to give your AI agent package-specific instructions.

Testing

Run the suite in parallel with composer test-parallel.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-addressable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^11.23|^12.0|^13.0
matanyadaev/laravel-eloquent-spatial Version ^4.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package masterix21/laravel-addressable contains the following files

Loading the files please wait ...