roundly-consulting / contacts-for-laravel
Store and query contacts for any entity or category in a Laravel application.
Package info
github.com/roundly-consulting/contacts-for-laravel
pkg:composer/roundly-consulting/contacts-for-laravel
Fund package maintenance!
Requires
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.4
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Contacts for Laravel
Typed, validated contacts for any Laravel model — emails, phones, addresses, URLs, social handles and custom kinds on a user, company or order. Values are normalized before they are stored, every owner keeps one primary per kind, and contacts can be verified with a code and exported as vCard.
Installation
Requires PHP 8.4, Laravel 12 or 13.
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
If your owner models have UUID/ULID keys, set CONTACTS_KEY_TYPE before migrating.
Usage
Add HasContacts to any model:
use RoundlyConsulting\Contacts\Concerns\HasContacts; class User extends Model { use HasContacts; }
Add, read and export contacts through the facade:
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 — the package issues the code, your app delivers it:
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
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/contacts-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md for details.