PHP code example of chuckcms / laravel-contacts

1. Go to this page and download the library: Download chuckcms/laravel-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/ */

    

chuckcms / laravel-contacts example snippets




namespace App\Models;

use Chuckcms\Contacts\Traits\HasContacts;
use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    use HasContacts;

    // ...
} 

$company = Company::first();
$company->addContact([
	'first_name' 				=> 'John', // / defaults to: null
	'email' 				=> '[email protected]', // defaults to: null
	'is_public'				=> true, // defaults to: false
	'is_primary'				=> true, // defaults to: false
]);

use Chuckcms\Contacts\Models\Contact;

$contact = Contact::first();
$company = Company::first();

$company->assignContact($contact);

$company = Company::first();
$contact = $company->getPrimaryContact();

$company->updateContact($contact, ['middle_name' => 'In The Middle']);

$company = Company::first();
$contact = $post->contacts()->first();

$company->removeContact($contact);

use Chuckcms\Contacts\Models\Contact;

$contacts = Contact::isPublic();
$company = Company::first();

$company->syncContacts($contacts);
// OR
$contacts = Contact::isPrimary()->pluck('id')->toArray();
$company->syncContacts($contacts);
// OR
$contact = Contact::isPrimary()->first();
$company->syncContacts($contact->id);

$company = Company::first();
$contact = $company->contacts()->first();

$company->deleteContact($contact);

$company = Company::first();

if ($company->hasContacts()) {
	//do something
}

use Chuckcms\Contacts\Models\Contact;

$company = Company::find();
$contact = Contact::first();

if ($company->hasContact($contact)) {
	//do something
}

//OR
if ($company->hasContact($contact->id)) {
	//do something
}

//OR
$contacts = Contact::where('first_name', 'John')->get();
if ($company->hasContact($contacts)) {
	//do something
}

//OR
$contacts = Contact::where('last_name', 'Doe')->pluck('id')->toArray();
if ($company->hasContact($contacts)) {
	//do something
}

$company = Company::first();

$publicContact = $company->getPublicContact();

$company = Company::first();

$primaryContact = $company->getPrimaryContact();

$company = Company::first();

$first_names = $company->getContactFirstNames();
 php artisan vendor:publish --provider="Chuckcms\Contacts\ContactsServiceProvider" 
config/contacts.php
 php artisan migrate