PHP code example of whilesmart / eloquent-contacts

1. Go to this page and download the library: Download whilesmart/eloquent-contacts library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

whilesmart / eloquent-contacts example snippets


'controller' => \App\Http\Controllers\ContactController::class,
'resource' => \App\Http\Resources\ContactResource::class,
'response_formatter' => \App\Http\Responses\ContactResponseFormatter::class,
'route_actions' => ['index', 'store', 'show'],
'route_write_middleware' => ['workspace.write'],

use Whilesmart\Contacts\Traits\HasContacts;

class Customer extends Model
{
    use HasContacts;
}

$customer->contacts()->create([
    'owner_type' => Workspace::class,
    'owner_id' => $workspaceId,
    'first_name' => 'Jane',
    'last_name' => 'Doe',
    'email' => '[email protected]',
    'title' => 'Accounts Payable',
    'address' => '12 Market St, Douala',
    'is_primary' => true,
]);

$customer->primaryContact?->email;       // recipient for billing
$customer->primaryContact?->full_name;   // "Jane Doe"

// config/contacts.php
'model' => \App\Models\Contact::class,