LaravelPackages.net
Acme Inc.
Toggle sidebar
zoparga/laravel-multi-address

Add many address to many model with a single trait. E.g.: many shipping address for a customer.

90
0
0.2.1
About zoparga/laravel-multi-address

zoparga/laravel-multi-address is a Laravel package for add many address to many model with a single trait. e.g.: many shipping address for a customer.. It currently has 0 GitHub stars and 90 downloads on Packagist (latest version 0.2.1). Install it with composer require zoparga/laravel-multi-address. Discover more Laravel packages by zoparga or browse all Laravel packages to compare alternatives.

Last updated

Add many address to many model with a single trait. E.g.: many shipping address for a customer.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require zoparga/laravel-multi-address

You can publish and run the migrations with:

php artisan vendor:publish --provider="zoparga\MultiAddress\MultiAddressServiceProvider" --tag="multi-address-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="zoparga\MultiAddress\MultiAddressServiceProvider" --tag="laravel-multi-address-config"

This is the contents of the published config file:

Usage

  • publish migration file
  • migrate
  • add trait to model
  • use it

Prepare model

use zoparga\MultiAddress\Traits\MultiAddresseableTrait;

class {{model}} extends Model { use MultiAddresseableTrait; }


$model = \App\Models\Model::find(1);

$model->multiaddresses()->create([
        'type' => 'YOUR VALUE',
        'country' => 'YOUR VALUE',
        'zip' => 'YOUR VALUE',
        'city' => 'YOUR VALUE',
        'street' => 'YOUR VALUE',
        'address_longitude' => 'YOUR VALUE',
        'address_latitude' => 'YOUR VALUE',
]);

$multiAddressId = 1;

$model->updateMultiAddress($multiAddressId, [
        'type' => 'YOUR VALUE',
        'country' => 'YOUR VALUE',
        'zip' => 'YOUR VALUE',
        'city' => 'YOUR VALUE',
        'street' => 'YOUR VALUE',
        'address_longitude' => 'YOUR VALUE',
        'address_latitude' => 'YOUR VALUE',
]);

Get the addresses, order by ID - desc
Or you can limit it here
$model->getLatestMultiAddresses()->get();

Or you can limit it here
$model->getLatestMultiAddresses()->limit(3)->get();

Of course you can get last created address
$model->getLastMultiAddress();


Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

Comments