Looking to hire Laravel developers? Try LaraJobs

connections-for-laravel maintained by roundly-consulting

Description
Many-to-many connections between Eloquent models with permissions and expirations.
Last update
2026/10/03 19:56 (dev-main)
License
Downloads
30

Comments
comments powered by Disqus

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.

License

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