HasPermissions
trait HasPermissions
Traits
Build Permission relations from one immutable partition and team snapshot.
Methods
Build a partition-aware belongs-to-many relation.
Build a partition-aware morph-to-many relation.
Build the related query using the relation's captured partition.
Ensure a partition-bearing relation parent belongs to the captured partition.
Apply the captured partition to pivot reads and writes.
Get the permission registrar.
Get the event dispatcher.
Boot permission cleanup and queued assignment handling.
Delete one kind of assignment for a hard-deleted subject.
Delete assignment pivots owned by a Role or Permission record.
Get the permission model class.
Get the wildcard permission class.
A model may have multiple direct permissions.
Build the direct permission assignment relation for a captured context.
Get cached direct permission assignments for this model.
Return allowed direct permissions.
Scope the model query to certain permissions only.
Add an effective permission predicate for the given permission ids.
Add a permission-effect predicate for direct and role-granted permissions.
Add a direct permission-effect predicate.
Add a role permission-effect predicate.
Scope the model query to only those without certain permissions, whether indirectly by role or by direct permission.
No description
Find a permission.
Determine if the model may perform the given permission.
Validates a wildcard permission against all permissions of a user.
An alias to hasPermissionTo(), but avoids throwing an exception.
Determine if the model has any of the given permissions.
Determine if the model has all of the given permissions.
Determine if the model has, via roles, the given permission.
Determine if the model has the given permission.
Return all the permissions the model has via roles.
Return all the permissions the model has, both directly and via roles.
Grant the given permission(s) to the model.
Deny the given permission(s) for the model.
Build a collision-safe assignment ID identity.
Index assignment IDs by their collision-safe identities.
Normalize an ID read directly from an assignment pivot.
Read current assignment pivots through their captured relation constraints.
Insert permission assignments into an empty assignment set.
Queue permission assignments until the model is saved.
Remove permission assignments queued for a captured context.
Flush permission assignments queued before the model was saved.
Attach collapsed queued permission assignment batches.
Clear queued permission assignments after their transaction commits.
Invalidate the captured contexts of committed permission assignments.
Collapse queued permission assignments to their final edge state.
Dispatch the permission attached event when enabled and listened for.
Determine whether the permission attached event has listeners.
Forget the wildcard permission index.
Remove all current permissions and set the given ones.
Remove all current permissions and set allowed and denied permissions.
Revoke the given permission(s).
Dispatch the permission detached event when enabled and listened for.
Determine whether the permission detached event has listeners.
Determine if the model has an explicit denied direct permission.
Determine if the model has an explicit denied permission via roles.
Return permissions granted through the model's roles with role-permission pivot data.
Load permissions granted through the model's roles with role-permission pivot data.
Resolve a permission for matching without throwing.
Build lookup keys for denied permissions.
Clone a permission with the matching role-permission pivot.
Normalize a permission assignment effect.
Determine if a stored permission matches an input permission.
Resolve the guard to use when matching stored permissions.
Get the permission names.
No description
Get the guard names for the model.
Get the default guard name for the model.
Forget the cached permissions.
Check if the model has All of the requested Direct permissions.
Check if the model has Any of the requested Direct permissions.
Details
in
BuildsPermissionRelations at line 35
protected BelongsToMany
permissionBelongsToMany(string $related, string $table, string $foreignPivotKey, string $relatedPivotKey, string $relationName, PermissionRelationContext|null $context = null)
Build a partition-aware belongs-to-many relation.
in
BuildsPermissionRelations at line 72
protected MorphToMany
permissionMorphToMany(string $related, string $table, string $foreignPivotKey, string $relatedPivotKey, string $relationName, bool $inverse = false, bool $teamScoped = false, PermissionRelationContext|null $context = null)
Build a partition-aware morph-to-many relation.
in
BuildsPermissionRelations at line 129
protected Builder
permissionRelationQuery(Model $related, PermissionPartition|null $partition)
Build the related query using the relation's captured partition.
in
BuildsPermissionRelations at line 144
protected void
ensurePermissionRelationParentMatches(PermissionRegistrar $registrar, PermissionPartition|null $partition)
Ensure a partition-bearing relation parent belongs to the captured partition.
in
BuildsPermissionRelations at line 178
protected BelongsToMany
applyPermissionPartitionToRelation(BelongsToMany $relation, PermissionPartition|null $partition)
Apply the captured partition to pivot reads and writes.
at line 51
protected PermissionRegistrar
permissionRegistrar()
Get the permission registrar.
at line 59
protected Dispatcher
eventDispatcher()
Get the event dispatcher.
at line 67
static void
bootHasPermissions()
Boot permission cleanup and queued assignment handling.
at line 122
static protected array|null
deleteSubjectAssignments(Model $model, string $table)
Delete one kind of assignment for a hard-deleted subject.
at line 213
static protected void
deletePermissionRecordAssignments(Model $model, string $modelAssignmentsTable, string $pivotKey)
Delete assignment pivots owned by a Role or Permission record.
at line 263
string
getPermissionClass()
Get the permission model class.
at line 275
string
getWildcardClass()
Get the wildcard permission class.
at line 297
BelongsToMany
permissions()
A model may have multiple direct permissions.
at line 305
protected BelongsToMany
permissionAssignmentRelation(PermissionRelationContext|null $context = null)
Build the direct permission assignment relation for a captured context.
at line 325
protected Collection
getCachedDirectPermissions()
Get cached direct permission assignments for this model.
at line 399
protected Collection
allowedDirectPermissions()
Return allowed direct permissions.
at line 411
Builder
scopePermission(Builder $query, array|Collection|int|Permission|string|UnitEnum $permissions, bool $without = false)
Scope the model query to certain permissions only.
at line 431
protected Builder
whereEffectivePermission(Builder $query, array $permissionIds)
Add an effective permission predicate for the given permission ids.
at line 456
protected Builder
wherePermissionEffect(Builder $query, int|string $permissionId, bool $denied)
Add a permission-effect predicate for direct and role-granted permissions.
at line 476
protected Builder
whereDirectPermissionEffect(Builder $query, int|string $permissionId, bool $denied)
Add a direct permission-effect predicate.
at line 491
protected Builder
whereRolePermissionEffect(Builder $query, int|string $permissionId, bool $denied)
Add a role permission-effect predicate.
at line 506
Builder
scopeWithoutPermission(Builder $query, array|Collection|int|Permission|string|UnitEnum $permissions)
Scope the model query to only those without certain permissions, whether indirectly by role or by direct permission.
at line 516
protected array
convertToPermissionModels(array|Collection|int|Permission|string|UnitEnum $permissions)
No description
at line 549
Permission
filterPermission(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
Find a permission.
at line 586
bool
hasPermissionTo(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
Determine if the model may perform the given permission.
at line 618
protected bool
hasWildcardPermission(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
Validates a wildcard permission against all permissions of a user.
at line 649
bool
checkPermissionTo(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
An alias to hasPermissionTo(), but avoids throwing an exception.
at line 663
bool
hasAnyPermission(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Determine if the model has any of the given permissions.
at line 681
bool
hasAllPermissions(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Determine if the model has all of the given permissions.
at line 697
protected bool
hasPermissionViaRole(Permission $permission)
Determine if the model has, via roles, the given permission.
at line 720
bool
hasDirectPermission(int|Permission|string|UnitEnum $permission)
Determine if the model has the given permission.
at line 734
Collection
getPermissionsViaRoles()
Return all the permissions the model has via roles.
at line 749
Collection
getAllPermissions()
Return all the permissions the model has, both directly and via roles.
at line 800
HasPermissions
givePermissionTo(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Grant the given permission(s) to the model.
at line 810
HasPermissions
denyPermissionTo(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Deny the given permission(s) for the model.
at line 898
protected string
assignmentIdIdentity(int|string $id)
Build a collision-safe assignment ID identity.
at line 909
protected array
indexAssignmentIds(array $ids)
Index assignment IDs by their collision-safe identities.
at line 923
protected int|string
normalizeRelatedPivotId(BelongsToMany $relation, mixed $id)
Normalize an ID read directly from an assignment pivot.
at line 936
protected Collection
readCurrentAssignmentPivots(BelongsToMany $relation, array $columns, array|null $ids = null)
Read current assignment pivots through their captured relation constraints.
at line 1091
protected void
attachPermissionAssignments(array $permissions, array $pivot, PermissionRelationContext|null $context = null)
Insert permission assignments into an empty assignment set.
at line 1112
protected void
queuePermissionAssignments(array $permissions, array $pivot, PermissionRelationContext $context)
Queue permission assignments until the model is saved.
at line 1185
protected bool
removeQueuedPermissionAssignments(array $permissions, PermissionRelationContext $context)
Remove permission assignments queued for a captured context.
at line 1227
protected void
flushQueuedPermissionAssignments()
Flush permission assignments queued before the model was saved.
at line 1249
protected void
attachQueuedPermissionAssignmentBatches(array $assignments)
Attach collapsed queued permission assignment batches.
at line 1263
protected void
clearQueuedPermissionAssignments()
Clear queued permission assignments after their transaction commits.
at line 1273
protected void
invalidateQueuedPermissionAssignmentContexts(array $assignments)
Invalidate the captured contexts of committed permission assignments.
at line 1300
protected array
collapseQueuedPermissionAssignments()
Collapse queued permission assignments to their final edge state.
at line 1342
protected void
dispatchPermissionAttachedEvent(array $permissions)
Dispatch the permission attached event when enabled and listened for.
at line 1354
protected bool
permissionAttachedEventIsListenedFor()
Determine whether the permission attached event has listeners.
at line 1363
void
forgetWildcardPermissionIndex()
Forget the wildcard permission index.
at line 1375
HasPermissions
syncPermissions(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Remove all current permissions and set the given ones.
at line 1440
array
syncPermissionEffects(array|Collection $allowed = [], array|Collection $denied = [])
Remove all current permissions and set allowed and denied permissions.
For unsaved models, assignments are queued until the model is saved and the returned change set is empty because no database rows are changed yet.
at line 1513
HasPermissions
revokePermissionTo(Permission|Permission[]|string|string[]|UnitEnum $permission)
Revoke the given permission(s).
at line 1558
protected void
dispatchPermissionDetachedEvent(mixed $permission)
Dispatch the permission detached event when enabled and listened for.
at line 1570
protected bool
permissionDetachedEventIsListenedFor()
Determine whether the permission detached event has listeners.
at line 1581
bool
hasDeniedPermission(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
Determine if the model has an explicit denied direct permission.
at line 1597
bool
hasDeniedPermissionViaRoles(int|Permission|string|UnitEnum $permission, string|null $guardName = null)
Determine if the model has an explicit denied permission via roles.
at line 1634
protected Collection
getPermissionsViaRolesWithPivots()
Return permissions granted through the model's roles with role-permission pivot data.
at line 1653
protected Collection
loadPermissionsViaRolesWithPivots()
Load permissions granted through the model's roles with role-permission pivot data.
at line 1679
protected Model|null
permissionForMatch(mixed $permission, string $guardName)
Resolve a permission for matching without throwing.
at line 1711
protected array
deniedPermissionKeys(Collection ...$permissionCollections)
Build lookup keys for denied permissions.
at line 1729
protected string
permissionComparisonKey(Model $permission)
Build a permission comparison key.
at line 1737
protected Model
permissionWithRolePivot(Model $permission, Model $role)
Clone a permission with the matching role-permission pivot.
at line 1748
protected bool
pivotIsDenied(Model $model)
Determine if a hydrated pivot marks the permission as denied.
at line 1763
protected bool
permissionEffectIsDenied(mixed $value)
Normalize a permission assignment effect.
at line 1772
protected Collection
relationCollection(Model $model, string $relation)
Get a hydrated relation collection.
at line 1793
protected bool
storedPermissionMatches(Model $storedPermission, mixed $permission, string|null $guardName = null)
Determine if a stored permission matches an input permission.
at line 1816
protected string
guardNameForPermissionMatch(mixed $permission, string|null $guardName = null)
Resolve the guard to use when matching stored permissions.
at line 1843
Collection
getPermissionNames()
Get the permission names.
at line 1852
protected Collection|Permission|Permission[]
getStoredPermission(array|Collection|int|Permission|string|UnitEnum $permissions, PermissionPartition|null $partition = null)
No description
at line 1940
protected void
ensureModelSharesGuard(Permission|Role $roleOrPermission)
No description
at line 1950
protected Collection
getGuardNames()
Get the guard names for the model.
at line 1958
protected string
getDefaultGuardName()
Get the default guard name for the model.
at line 1966
void
forgetCachedPermissions()
Forget the cached permissions.
at line 1976
bool
hasAllDirectPermissions(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Check if the model has All of the requested Direct permissions.
at line 1994
bool
hasAnyDirectPermission(array|Collection|int|Permission|string|UnitEnum ...$permissions)
Check if the model has Any of the requested Direct permissions.