Skip to content

adhalwala/contactable

Repository files navigation

Add multiple contacts for a User

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Installation

You can install the package via composer:

composer require aecor/contactable

You can publish and run the migrations with:

php artisan vendor:publish --provider="Aecor\Contact\ContactServiceProvider" --tag="migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Aecor\Contact\ContactServiceProvider" --tag="config"

This is the contents of the published config file:

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

Usage and few examples

Prepare your model

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Aecor\Contact\Traits\HasContact;

class YourModel extends Model
{
    use HasContact;
}

Get instance of your model

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

Add a single contact

$user->addContact([
    'type' => 'phone',
    'value' => '9999999999',
    'custom_attributes' => [
        'sub_type' => 'office'
    ],                          // Optional field
    'order_column' => 1         // Optional field
]);

Add multiple contacts

$user->addManyContacts([
    [
        'type' => 'phone',
        'value' => '9999999999',
    ],
    [
        'type' => 'mobile',
        'value' => '8888888888',
    ],
    [
        'type' => 'email',
        'value' => 'john@example.com',
    ],
]);

Get all contacts

$user->contacts;

Get contacts with condition

$user->contacts()->where('type', 'mobile')->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.