All packages
Contacts for Laravel
Query scopes
Every scope works on Contact::query() and on an owner’s contacts() relation, and they combine freely:
use RoundlyConsulting\Contacts\Enums\ContactType;
use RoundlyConsulting\Contacts\Models\Contact;
Contact::query()->forOwner($user)->get();
Contact::query()->forOwner(owner: $user, includeAlsoWithoutOwner: true)->get();
Contact::query()->withoutOwner()->get();
Contact::query()->forCategory('Utility')->get();
Contact::query()->withoutCategory()->get();
Contact::query()->ofType(ContactType::Email)->get(); // or ->ofType('email')
Contact::query()->primary()->get();
Contact::query()->verified()->get(); // ->verified(false) for unverified
Contact::query()->pendingVerification()->get(); // unverified, token issued
Contact::query()->search('alice')->get(); // name / value / label LIKE
Contact::query()->ordered()->get(); // by position, then idScope reference
| Scope | Matches |
|---|---|
forOwner(Model $owner, bool $includeAlsoWithoutOwner = false) | Contacts of one owner, optionally plus ownerless ones. |
withoutOwner() | Contacts with no owner. |
forCategory(string $category) | Contacts in a category. |
withoutCategory() | Contacts with no category. |
ofType(ContactType|string $type) | One kind — built-in or a registered custom kind. |
primary() | Primary contacts only. |
verified(bool $verified = true) | Verified — or unverified with false. |
pendingVerification() | Unverified contacts holding a token. |
search(string $term) | Case-insensitive contains match on name, value or label; wildcards escaped; empty term is a no-op. |
ordered() | Sort by position, then id. |
Combining scopes
// A company's verified supplier emails matching a domain, in position order
Contact::query()
->forOwner($company)
->forCategory('Suppliers')
->ofType(ContactType::Email)
->verified()
->search('example.com')
->ordered()
->get();search() uses ILIKE on PostgreSQL and LIKE elsewhere, with % and _ in the term escaped so they match literally on every driver.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.