Affiliations & relationships
A Contact is Connectable through connections-for-laravel. Link contacts to each other and to owners with a free-form, config-driven relationship kind:
$person->connectTo($company, ['employee']); // raw connection
$person->relateTo($company, 'works_at'); // typed kind, stored in meta
$person->relationsOfKind('works_at'); // contacts related under a kind
$person->inviteConnection($company); // pending -> accept/block
$company->acceptConnectionFrom($person);
Contacts::sharedWith($owner); // contacts connected to an owner- relateTo(Connectable $other, string $kind, array $meta = []) — stores the kind in the connection’s meta, merged over any extra meta you pass. Relating twice is idempotent.
- relationsOfKind(string $kind) — the contacts this contact is related to under that kind.
- Relating a contact to itself throws RelationshipException.
- Contacts::sharedWith($owner) — contacts connected to an owner, so one shared contact (a supplier, say) can belong to many owners without duplication. The owner must be Connectable.
Connections API
The full connections API is available on every contact — invitations, blocking, expiry and removal:
$person->relateTo($company, 'works_at', ['since' => '2024-03']); // extra meta
$person->relateTo($company, 'works_at'); // idempotent — still one edge
$person->connectTo($consultant, ['contractor'], now()->addDays(30)); // expiring edge
$person->expiringConnections(); // edges expiring within 7 days
$person->disconnectFrom($consultant);
$company->blockConnectionFrom($person);Restricting relationship kinds
Restrict the allowed kinds with contacts.relationship_kinds. Relating under any other kind throws RelationshipException:
// config/contacts.php — empty = free-form; a list or a kind => label map restricts kinds
'relationship_kinds' => [
'works_at' => 'Works at',
'spouse_of' => 'Spouse of',
'reports_to' => 'Reports to',
],Soft-deleting a contact trashes its relationship edges in both directions, restore() brings them back and forceDelete() removes them for good.
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.