<?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