### Install Contacts for Laravel via Composer and Publish Migrations Source: https://github.com/roundly-consulting/contacts-for-laravel/blob/main/README.md Run these commands to install the package and publish the required migration files. Requires PHP 8.4 and Laravel 12 or 13. Set CONTACTS_KEY_TYPE before migrating if your owner models use UUID/ULID keys. ```bash composer require roundly-consulting/contacts-for-laravel php artisan vendor:publish --tag="addresses-migrations" php artisan vendor:publish --tag="connections-migrations" php artisan vendor:publish --tag="contacts-migrations" php artisan migrate ``` -------------------------------- ### Add HasContacts Trait to a Laravel Model Source: https://github.com/roundly-consulting/contacts-for-laravel/blob/main/README.md Use the HasContacts trait on any model to enable contact management. The example shows a User model using the trait. ```php use RoundlyConsulting\Contacts\Concerns\HasContacts; class User extends Model { use HasContacts; } ``` -------------------------------- ### Add, Read, and Export Contacts via Contacts Facade Source: https://github.com/roundly-consulting/contacts-for-laravel/blob/main/README.md Demonstrates adding email and phone contacts with normalization, retrieving primary and typed contacts, and exporting a vCard string. Values are normalized before storage; primary contacts are per kind. ```php use RoundlyConsulting\Contacts\Enums\ContactType; use RoundlyConsulting\Contacts\Facades\Contacts; Contacts::for($user)->email(' A.Person@Example.COM ')->label('Work')->primary()->add(); Contacts::for($user)->phone('+421 900 000 000')->label('Mobile')->add(); Contacts::for($user)->primary(ContactType::Email)?->value; // 'a.person@example.com' Contacts::for($user)->ofType(ContactType::Phone); // ordered by position Contacts::for($user)->vCard(); // a vCard 3.0 string ``` -------------------------------- ### Verify a Contact with Verification Code Source: https://github.com/roundly-consulting/contacts-for-laravel/blob/main/README.md Shows how to listen for the ContactVerificationRequested event to deliver the token, and how to request and confirm verification. The code is stored only as a hash; confirm sets verified_at or throws. ```php 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 ```