Search by

roundly-consulting / connections-for-laravel

mihaliak

Many-to-many connections between Eloquent models with permissions and expirations.

Package info

github.com/roundly-consulting/connections-for-laravel

pkg:composer/roundly-consulting/connections-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 30

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 17:56 UTC

This package is auto-updated.

Last update: 2026-10-03 18:05:18 UTC


README

Connections for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

Connections for Laravel

Many-to-many connections between any Eloquent models — a user to a team, an organization to a project — each with its own permissions, an optional expiry and an invitation flow (pending → accepted / blocked). Expired connections grant nothing and prune themselves.

Installation

Requires PHP 8.4, and Laravel 12 or 13.

composer require roundly-consulting/connections-for-laravel
php artisan vendor:publish --tag="connections-migrations"
php artisan migrate

If your connected models use UUID or ULID keys, set CONNECTIONS_KEY_TYPE=uuid / ulid before migrating.

Usage

Make each model that takes part connectable (User the same way):

use Illuminate\Database\Eloquent\Model;
use RoundlyConsulting\Connections\Concerns\HasConnections;
use RoundlyConsulting\Connections\Contracts\Connectable;

class Team extends Model implements Connectable
{
    use HasConnections;
}

Connect a pair with permissions and an expiry, then check and change what it may do:

use RoundlyConsulting\Connections\Facades\Connections;

Connections::between($user, $team)
    ->withPermissions('view', 'posts.*')
    ->expiresIn(now()->addMonth())
    ->connect();

Connections::between($user, $team)->exists();                     // true — active connection
Connections::between($user, $team)->permissions()->has('posts.edit'); // true — wildcard match
Connections::between($user, $team)->permissions()->grant('publish');

$user->hasPermissionThroughConnection($team, 'publish');          // true

Connections::between($user, $team)->disconnect();                 // soft delete
Connections::prune();                                             // drop expired connections

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/connections-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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). See LICENSE.md.