PHP code example of roundly-consulting / contacts-for-laravel

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

    

roundly-consulting / contacts-for-laravel example snippets


use RoundlyConsulting\Contacts\Concerns\HasContacts;

class User extends Model
{
    use HasContacts;
}

use RoundlyConsulting\Contacts\Enums\ContactType;
use RoundlyConsulting\Contacts\Facades\Contacts;

Contacts::for($user)->email(' [email protected] ')->label('Work')->primary()->add();
Contacts::for($user)->phone('+421 900 000 000')->label('Mobile')->add();

Contacts::for($user)->primary(ContactType::Email)?->value;   // '[email protected]'
Contacts::for($user)->ofType(ContactType::Phone);              // ordered by position
Contacts::for($user)->vCard();                                 // a vCard 3.0 string

use RoundlyConsulting\Contacts\Events\ContactVerificationRequested;

Event::listen(function (ContactVerificationRequested $event): void {
    // send $event->plainToken to $event->contact->value by SMS or mail
});

$phone = Contacts::for($user)->primary(ContactType::Phone);

Contacts::verification()->request($phone);          // a 6-digit code, stored only as a hash
Contacts::verification()->confirm($phone, $code);   // sets verified_at, or throws
bash
composer vendor:publish --tag="addresses-migrations"
php artisan vendor:publish --tag="connections-migrations"
php artisan vendor:publish --tag="contacts-migrations"
php artisan migrate