roundly-consulting / connections-for-laravel
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!
Requires
- php: ^8.4
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.