Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Addresses Laravel Package

metamel/laravel-addresses

View on GitHub
Deep Wiki
Context7

Laravel-Addresses (Base on rinvex/laravel-addresses)


A polymorphic Laravel package to manage addresses. This package allow you to add addresses to any eloquent model with ease.

Packagist Issues Forks StyleCI License

Installation

  1. Install the package via composer:

    composer require metamel/laravel-addresses
    
  2. Publish config file:

    php artisan vendor:publish --tag=addresses-config
    
  3. Execute migrations via the following command:

    php artisan migrate
    
  4. Done!

Usage

To add addresses support to your eloquent models simply use \Metamel\Addresses\Traits\Addressable trait.

Manage your addresses

// Get instance of your model
$user = new \App\Models\User::find(1);

// Create a new address
$user->addresses()->create([
    'label' => 'Default Address',
    'name' => 'John Doe',
    'organization' => 'Something Went Wrong LTD.',
    'country_code' => 'gb',
    'street' => '10 Downing Street',
    'state' => 'somewhere over the rainbow',
    'city' => 'London',
    'postal_code' => 'SW1A 2AA',
    'latitude' => '51.503364',
    'longitude' => '-0.127625',
    'is_primary' => true,
    'is_billing' => true,
    'is_shipping' => true,
]);

// Create multiple new addresses
$user->addresses()->createMany([
    [...],
    [...],
    [...],
]);

// Find an existing address
$address = app('metamel.addresses.models.address')->find(1);

// Update an existing address
$address->update([
    'label' => 'Default Work Address',
]);

// Delete address
$address->delete();

// Alternative way of address deletion
$user->addresses()->where('id', 123)->first()->delete();

Manage your addressable model

The API is intuitive and very straight forward, so let's give it a quick look:

// Get instance of your model
$user = new \App\Models\User::find(1);

// Get attached addresses collection
$user->addresses;

// Get attached addresses query builder
$user->addresses();

// Scope Primary Addresses
$primaryAddresses = app('metamel.addresses.models.address')->isPrimary()->get();

// Scope Billing Addresses
$billingAddresses = app('metamel.addresses.models.address')->isBilling()->get();

// Scope Shipping Addresses
$shippingAddresses = app('metamel.addresses.models.address')->isShipping()->get();

// Scope Addresses in the given country
$egyptianAddresses = app('metamel.addresses.models.address')->InCountry('eg')->get();

// Find all users within 5 kilometers radius from the latitude/longitude 31.2467601/29.9020376
$fiveKmAddresses = \App\Models\User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376')->get();

// Alternative method to find users within certain radius
$user = new \App\Models\User();
$users = $user->lat('51.503364')->lng('-0.127625')->within(5, 'kilometers')->get();

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

License

This software is released under The MIT License (MIT).

(c) 2022 Metamel, Some rights reserved.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle