Skip to content
Nav

Subject resolution

composer require langsys/laravel-access-guard
Packagist version Monthly downloads License PHP 8.2+ Laravel 10 / 11 / 12

On each authorize() call, Access Guard:

  1. checks for a super admin (the resolved user implements Authorizable and isSuperAdmin() is true) → allow;
  2. otherwise picks the API key if one is present on the request, else the authenticated user;
  3. runs the key path (keyHasPermission and keyBelongsToEntity) or the user path (userRoleInEntity → the role’s hasPermission, and not userHasDisabledEntity).

By default the user comes from Auth::user() and the API key from the api_key request attribute (set by langsys/laravel-api-keys). Override either from a service provider:

AccessGuard::resolveUserUsing(fn () => /* ... */);
AccessGuard::resolveApiKeyUsing(fn () => /* ... */);
Feedback