Toggle, reconnect & restore
disconnect() soft-deletes the connection and fires ConnectionRemoved; it throws ConnectionNotFound when there is none. The trashed row keeps its place in the unique pair index, so a disconnected pair is always revived in place — never inserted twice:
Connections::between($user, $team)->disconnect(); // soft delete, fires ConnectionRemoved
$user->disconnectFrom($team); // the trait equivalentToggle, reconnect and restore
// Disconnect an active connection, otherwise connect — as often as you like. Over a pending,
// blocked or expired row the "connect" keeps that status and expiry (it never lifts a block
// or renews an expiry — use accept() / extend() for that).
Connections::between($user, $team)->toggle(); // ?Connection
$user->toggleConnection($team);
// Restore a previously soft-deleted connection with the permissions, expiry and meta it had
// (connect() would start it fresh), firing ConnectionRestored — or connect afresh if none trashed.
Connections::between($user, $team)->reconnect();
Connections::between($user, $team)->restore(); // alias
$user->reconnectTo($team);- toggle() disconnects an active connection and returns null; otherwise it connects and returns the Connection — as often as you like. toggleConnection() is the trait method and accepts permissions.
- The active check follows enforce_active_on_check, so a pending, blocked or expired connection counts as not connected. toggle() then connects over it but keeps that status and expiry — it never lifts a block or renews an expiry; use accept() or extend() for that.
- Switching a pair back on after a toggle-off revives the soft-deleted row as a fresh connection.
- reconnect() restores the soft-deleted row with the permissions, expiry and meta it had and fires ConnectionRestored. When nothing is trashed it connects afresh and fires ConnectionCreated instead. restore() is an alias; reconnectTo() is the trait method.
Restore it, or start over
After a disconnect() or a prune you choose how the pair comes back: reconnect() restores the old connection, connect() — like grant(), permissions()->sync(), invite(), toggle() and sync() — revives the row as a fresh connection with only what you stage plus the config defaults. A blocked pair stays blocked either way:
Connections::between($user, $team)->disconnect();
// Restore it as it was — permissions, expiry and meta (ConnectionRestored).
Connections::between($user, $team)->reconnect();
// Or start over: connect() revives the soft-deleted row as a fresh connection (ConnectionCreated),
// with what you stage plus the config defaults — a blocked pair is restored still blocked.
Connections::between($user, $team)->withPermissions('view')->connect();Restored as it was
A restored connection comes back exactly as it was — permissions, status, meta and expiry included. Connections soft-deleted by connections:prune can be restored too, but their expiry is still in the past, so renew it:
Connections::between($user, $team)->disconnect();
// Later — bring the same connection back, then renew a lapsed expiry.
Connections::between($user, $team)->reconnect();
Connections::between($user, $team)->extend(now()->addMonth());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.