PHPackages                             xcopy/laravel-contacts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. xcopy/laravel-contacts

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

xcopy/laravel-contacts
======================

A simple Laravel package for managing polymorphic contact information for any Eloquent model.

v1.0.0(2mo ago)02↑2900%MITPHPPHP ^8.1CI passing

Since Feb 24Pushed 1mo agoCompare

[ Source](https://github.com/xcopy/laravel-contacts)[ Packagist](https://packagist.org/packages/xcopy/laravel-contacts)[ Docs](https://github.com/xcopy/laravel-contacts)[ GitHub Sponsors](https://github.com/xcopy)[ RSS](/packages/xcopy-laravel-contacts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (17)Versions (2)Used By (0)

Laravel Contacts
================

[](#laravel-contacts)

[![GitHub Tests Action Status](https://camo.githubusercontent.com/103956590e18278b89f5362de5fb7338874c973b689005958da34757dfade7a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78636f70792f6c61726176656c2d636f6e74616374732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/xcopy/laravel-contacts/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/8856101e3f9c6f22a44eb2e804550e34527a669cc0b812c5da4aec79ff7d5540/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78636f70792f6c61726176656c2d636f6e74616374732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/xcopy/laravel-contacts/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/935210c0b4c4789c2806f059bb51cb23377bb65fead5f73af30d87f1970f44bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f78636f70792f6c61726176656c2d636f6e74616374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xcopy/laravel-contacts)

A simple Laravel package for managing polymorphic contact information (phone, email, mobile, WhatsApp, Telegram, website, etc.) for any Eloquent model. Perfect for multi-tenant SaaS applications, CRMs, or property management systems where multiple entities need contact details.

Features
--------

[](#features)

- **Polymorphic relationships**: Attach contacts to any Eloquent model
- **Multiple contact types**: Phone, Email, WhatsApp, Telegram, Website, and Other
- **Smart value handling**: Automatic validation and normalization via strategy pattern
- **Primary &amp; verified flags**: Mark contacts as primary or verified
- **Unique constraints**: Prevents duplicate contacts per model
- **Type-safe**: Uses PHP 8.1+ enums and strict typing

Installation
------------

[](#installation)

```
composer require xcopy/laravel-contacts

```

Run the installation commands:

```
php artisan vendor:publish --provider="Jenishev\Laravel\Contacts\ContactsServiceProvider" --tag=config
php artisan vendor:publish --provider="Jenishev\Laravel\Contacts\ContactsServiceProvider" --tag=migrations
php artisan migrate
```

Usage
-----

[](#usage)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

Add the `HasContacts` trait to any model that needs contact information:

```
use Illuminate\Database\Eloquent\Model;
use Jenishev\Laravel\Contacts\Concerns\HasContacts;

class Company extends Model
{
    use HasContacts;

    // ... your model code
}
```

### 2. Create contacts

[](#2-create-contacts)

```
use Jenishev\Laravel\Contacts\Enums\ContactTypeEnum;

$company = Company::find(1);

// Create a primary email contact
$company->contacts()->create([
    'type' => ContactTypeEnum::Email,
    'value' => 'info@company.com',
    'is_primary' => true,
    'is_verified' => true,
]);

// Create a phone contact
$company->contacts()->create([
    'type' => ContactTypeEnum::Phone,
    'value' => '+1234567890',
    'is_primary' => false,
]);

// Create a WhatsApp contact
$company->contacts()->create([
    'type' => ContactTypeEnum::Whatsapp,
    'value' => '+1234567890',
]);
```

### 3. Retrieve contacts

[](#3-retrieve-contacts)

```
// Get all contacts
$contacts = $company->contacts;

// Get contacts of a specific type
$emails = $company->contacts()->where('type', ContactTypeEnum::Email)->get();

// Get primary contact
$primaryContact = $company->contacts()->where('is_primary', true)->first();

// Get verified contacts
$verified = $company->contacts()->where('is_verified', true)->get();
```

### 4. Value validation &amp; normalization

[](#4-value-validation--normalization)

Contact values are automatically validated and normalized based on their type:

```
// Email: lowercased and validated
$company->contacts()->create([
    'type' => ContactTypeEnum::Email,
    'value' => 'User@Example.COM', // stored as: user@example.com
]);

// Phone: formatted to E.164
$company->contacts()->create([
    'type' => ContactTypeEnum::Phone,
    'value' => '0555123456', // stored as: +996555123456
    'country_code' => 'KG',  // optional, defaults to config
]);

// Telegram: normalized username
$company->contacts()->create([
    'type' => ContactTypeEnum::Telegram,
    'value' => '@UserName', // stored as: username, retrieved as: @username
]);

// Website: normalized URL
$company->contacts()->create([
    'type' => ContactTypeEnum::Website,
    'value' => 'example.com', // stored as: https://example.com
]);

// WhatsApp: formatted to E.164
$company->contacts()->create([
    'type' => ContactTypeEnum::Whatsapp,
    'value' => '0555123456', // stored as: +996555123456
    'country_code' => 'KG',
]);
```

**Validation rules:**

- **Email**: Valid email format, lowercased
- **Phone**: Valid phone number for country, formatted per config (default: NATIONAL)
- **WhatsApp**: Valid phone number for country, E.164 format
- **Telegram**: 5–32 chars, alphanumeric and underscore, no consecutive/leading/trailing underscores
- **Website**: Valid URL, auto-adds `https://` if missing
- **Other**: No validation, stored as-is

### 5. Phone number formatting

[](#5-phone-number-formatting)

Phone numbers support configurable formatting via `config/contacts.php`:

```
// Available formats: E164, INTERNATIONAL, NATIONAL, RFC3966
// See: \libphonenumber\PhoneNumberFormat constants

'phone_format_set' => \libphonenumber\PhoneNumberFormat::NATIONAL,  // Storage format
'phone_format_get' => \libphonenumber\PhoneNumberFormat::NATIONAL,  // Retrieval format
```

**Format examples:**

- **E164**: `+996555123456`
- **INTERNATIONAL**: `+996 555 123 456`
- **NATIONAL**: `0555 123 456` (default)
- **RFC3966**: `tel:+996-555-123456`

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance88

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

75d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00b9a5db4855c1ef50ec05482f605d3147cd096a0d4a199fdf711642fca0f7fc?d=identicon)[xcopy](/maintainers/xcopy)

---

Top Contributors

[![xcopy](https://avatars.githubusercontent.com/u/202339?v=4)](https://github.com/xcopy "xcopy (16 commits)")

---

Tags

contactsemaillaravelphonephpwebsitewhatsappphplaravelemailphonecontacts

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/xcopy-laravel-contacts/health.svg)

```
[![Health](https://phpackages.com/badges/xcopy-laravel-contacts/health.svg)](https://phpackages.com/packages/xcopy-laravel-contacts)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

5762.6M6](/packages/propaganistas-laravel-disposable-email)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

56770.5k](/packages/railsware-mailtrap-php)[wnx/laravel-sends

Keep track of outgoing emails in your Laravel application.

200427.3k](/packages/wnx-laravel-sends)[spatie/laravel-discord-alerts

Send a message to Discord

151408.0k](/packages/spatie-laravel-discord-alerts)[garethp/php-ews

A PHP Library to interact with the Exchange SOAP service

113610.3k4](/packages/garethp-php-ews)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
