aecor/addressable

Add multiple addresses for a User

1.0.3 2021-02-23 06:13 UTC

This package is auto-updated.

Last update: 2024-04-23 13:18:18 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Installation

You can install the package via composer:

composer require aecor/addressable

You can publish and run the migrations with:

php artisan vendor:publish --provider="Aecor\Address\AddressServiceProvider" --tag="migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Aecor\Address\AddressServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'table-name' => 'addresses'
];

Usage and few examples

Prepare your model

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Aecor\Address\Traits\HasAddress;

class YourModel extends Model
{
    use HasAddress;
}

Get instance of your model

$user = \App\Models\User::find(1);

Add a single contact

$user->addAddress([
    'type' => 'office',
    'unit' => 'A',
    'house_number' => '10',
    'street' => 'Some street',
    'suburb' => 'Some suburb',
    'postcode' => '123',
    'custom_attributes' => [
        'open_at' => '09:00',
        'close_at' => '06:00'
    ],                          // Optional field
    'order_column' => 1         // Optional field
]);

All the common fields are available in database given below, additionally you can store your own details as json in 'custom_attributes' field. All the fields are kept nullable to make it easy implementation.

'type'
'unit'
'house_number'
'street'
'suburb'
'postcode'
'city'
'state'
'latitude'
'longitude'
'custom_attributes' // json field to add any additional data
'order_column'

Add multiple contacts

$user->addManyAddresses([
    [
        'type' => 'home',
        'unit' => 'A',
        'house_number' => '10',
        'street' => 'Some street 1',
        'suburb' => 'Some suburb 1',
        'postcode' => '123',
    ],
    [
        'type' => 'office',
        'unit' => 'B',
        'house_number' => '1',
        'street' => 'Some street 2',
        'suburb' => 'Some suburb 2',
        'postcode' => '456',
    ]
]);

Get all contacts

$user->addresses;

Get contacts with condition

$user->addresses()->where('type', 'home')->get();

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.