NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

hasPermissionThroughConnection() — and everything built on it: the any/all variants, permissions()->has() / hasAny() / hasAll() and the Gate hook — memoises the resolved connection per connector–connectable pair, so a page that checks access many times queries once:

$user->hasPermissionThroughConnection($team, 'edit');               // queries once, then memoised
$user->hasPermissionThroughConnection($team, 'view');               // served from the cache
$user->hasPermissionThroughConnection($team, 'edit', force: true);  // re-query and refresh the entry

Connections::between($user, $team)->permissions()->revoke('edit');  // writes invalidate the pair
$user->hasPermissionThroughConnection($team, 'edit');               // false — no force needed
  • The cache stores the Connection row, not the answer, so status and expiry are evaluated at check time.
  • Every write through the package — facade, trait, actions, bulk verbs and sync — invalidates the affected pair; connections:prune and Connections::prune() drop the whole cache once they remove rows.
  • isConnectedTo() and the other connected-to checks always query the database.
  • Set cache.enabled to false to re-query on every check.

Cache lifetime

The cache is a scoped container instance, dropped at the start of every request and queued job — Octane and queue:work included — so a cached permission never outlives one. Within a single request or job it can still miss changes made outside the package’s write path, such as another process or a direct Eloquent update to a Connection. Pass force: true where freshness matters, disable the cache, or flush it mid-request through the facade:

use RoundlyConsulting\Connections\Facades\Connections;

Connections::flushCache();   // forget every memoised connection

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

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