---
title: "Connections for Laravel — docs | Roundly"
description: "Developer docs for Connections for Laravel: polymorphic model connections with permissions, expirations, invitations, bulk sync, events and a Gate hook."
url: https://roundly-consulting.com/open-source/docs/connections-for-laravel
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

Open source

# Connections for Laravel

Install

`composer require roundly-consulting/connections-for-laravel`

Requires: PHP ^8.4 · Laravel ^12.0|^13.0

[GitHub](https://github.com/roundly-consulting/connections-for-laravel) [Packagist](https://packagist.org/packages/roundly-consulting/connections-for-laravel) [Donate (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Patreon](https://www.patreon.com/cw/roundly)

## Overview

Many-to-many connections between Eloquent models, with per-connection permissions and optional expirations. Connect any model to any other — a user to a team, an organization to a project — record what each connection is allowed to do, walk it through a pending → accepted / blocked invitation flow, and let expired connections prune themselves. A fluent Connections facade, trait verbs, standalone actions, events, an opt-in Gate hook and a test fake keep every operation to one readable line. MIT-licensed, with no third-party runtime dependencies beyond Laravel and two small Roundly helper packages.

### What you get

#### Connect any model to any model

One polymorphic, directed connection per pair — a user to a team, an organization to a project. Re-connecting only changes what you pass.

#### Per-connection permissions

Grant, revoke, sync and clear permission sets; check one, any or all of them, with \* and posts.\* wildcards.

#### Invitations & status

Pending → accepted / blocked flows with enforced status transitions and events at every step. Only active connections grant access.

#### Expirations

expiresIn(), extend() and a default expiry window, plus a prune command and an expiring-soon event.

#### Bulk operations & sync

toMany()->connectAll() and friends, and from()->sync() reconciling an exact set into a typed SyncResult.

#### Facade, DI or actions

One Connections facade, an injectable ConnectionManager or single-purpose actions — plus nine lifecycle events and an opt-in Gate::before hook.

#### Test fake

Connections::fake() records facade, injected-manager and trait writes for assertions while still writing to your test database.

### Documentation

#### [Installation](https://roundly-consulting.com/open-source/docs/connections-for-laravel/installation.md)

Install via Composer, publish and run the migration, and optionally publish the config file.

#### [Configuration](https://roundly-consulting.com/open-source/docs/connections-for-laravel/configuration.md)

Every config key and its default — model, table, key type, cache, events, Gate, default permissions, status and expiry.

#### [Database schema](https://roundly-consulting.com/open-source/docs/connections-for-laravel/database-schema.md)

One polymorphic connections table — morph keys, jsonb permissions and meta, status, expiry, soft deletes and a unique pair index.

#### [Connectable models](https://roundly-consulting.com/open-source/docs/connections-for-laravel/connectable-models.md)

Add the HasConnections trait and Connectable contract to any model, scaffold with make:connectable, and use the trait verbs.

#### [The Connections facade](https://roundly-consulting.com/open-source/docs/connections-for-laravel/connections-facade.md)

The whole public API in one facade — between() and from() builders, the permissions() sub-accessor, expiring(), prune(), flushCache() and fake().

#### [DI and actions](https://roundly-consulting.com/open-source/docs/connections-for-laravel/actions.md)

Inject ConnectionManager instead of the facade, or run single-purpose actions — with the full facade-to-action map, DTOs and exceptions.

#### [Permissions](https://roundly-consulting.com/open-source/docs/connections-for-laravel/permissions.md)

Grant, revoke, sync and clear per-connection permissions; check one, any or all of them, with \* and segment wildcards.

#### [Invitations & status](https://roundly-consulting.com/open-source/docs/connections-for-laravel/invitations.md)

Model approval flows: create pending connections, accept or block them from either side, and use the ConnectionStatus enum helpers.

#### [Expirations](https://roundly-consulting.com/open-source/docs/connections-for-laravel/expirations.md)

Give connections an expiry, move or clear it, set a default window, and see how expiry affects access checks.

#### [Metadata](https://roundly-consulting.com/open-source/docs/connections-for-laravel/metadata.md)

Attach free-form context to a connection in a JSON meta bag, read it with dot access, and merge or replace it on re-connect.

#### [Bulk operations & sync](https://roundly-consulting.com/open-source/docs/connections-for-laravel/bulk-operations.md)

Connect, disconnect, grant and revoke across many connectables at once, or reconcile an exact set with from()->sync().

#### [Toggle, reconnect & restore](https://roundly-consulting.com/open-source/docs/connections-for-laravel/toggle-reconnect.md)

Disconnect with soft deletes, flip a connection with toggle(), and bring a removed one back as it was with reconnect() or fresh with connect().

#### [Querying connections](https://roundly-consulting.com/open-source/docs/connections-for-laravel/querying.md)

Check who is connected, walk both directions, filter with active, expired, expiring and permission scopes, and fetch typed models.

#### [Events](https://roundly-consulting.com/open-source/docs/connections-for-laravel/events.md)

Nine lifecycle events for creates, updates, removals, permission changes, invitations, status changes, restores and expiry warnings.

#### [Gate integration](https://roundly-consulting.com/open-source/docs/connections-for-laravel/gate.md)

Opt in to a Gate::before hook so $user->can('publish', $team) and Laravel’s other authorization checks resolve through connections.

#### [Caching](https://roundly-consulting.com/open-source/docs/connections-for-laravel/caching.md)

Permission checks are memoised per connector–connectable pair, invalidated on every package write, and bypassable with force: true.

#### [Artisan commands](https://roundly-consulting.com/open-source/docs/connections-for-laravel/commands.md)

Prune expired connections, dispatch expiring-soon events, scaffold connectable models, and schedule the maintenance.

#### [Custom connection model](https://roundly-consulting.com/open-source/docs/connections-for-laravel/custom-model.md)

Swap in your own Connection subclass via connections.model to add behaviour, and wire optional integrations such as reports-for-laravel.

#### [Testing](https://roundly-consulting.com/open-source/docs/connections-for-laravel/testing.md)

Record every write with Connections::fake() — facade, injected manager and trait — assert each operation, and seed rows with the factory.

#### [Requirements](https://roundly-consulting.com/open-source/docs/connections-for-laravel/requirements.md)

PHP 8.4+, Laravel 12 or 13, and two Roundly helper packages that Composer installs automatically.

## 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source.md)
