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'
];
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' => '[email protected]',
],
]);
Get all contacts
$user->contacts;
Get contacts with condition
$user->contacts()->where('type', 'mobile')->get();
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.