PermissionRelations
extends Model
in package
implements
PermissionsInterface
Uses
Uuid, PolymorphicRelations, Permissions, Find
Permissions database model
Table of Contents
Interfaces
- PermissionsInterface
- Permissions interface
Constants
Properties
- $timestamps : bool
- Disable timestamps
- $DEFAULT_UUID_COLUMN : string
- Default uuid column name
- $fillable : array<string|int, mixed>
- Fillable attributes
- $relationColumnName : string
- Reation column name
- $relationModelClass : string
- Relation model class
- $table : string
- Db table name
Methods
- addPermisionType() : bool
- Add permission type
- addPermission() : bool
- Add permission item.
- bootUuid() : void
- Init model events.
- deletePermission() : bool
- Delete permission for user or group
- deleteRelation() : bool
- Delete relation
- deleteRelations() : bool
- Delete relations
- findByColumn() : Model|null
- Find model by column name
- findById() : Model|null
- Find model by id or uuid
- findByIdQuery() : Builder
- Return query builder
- findItems() : QueryBuilder|false
- Find collection of models by id or uuid
- findMultiple() : Builder
- Find multiole query
- findQuery() : Builder
- Return query builder
- getGroupPermission() : Model|bool
- Get group permission
- getGroupPermissions() : mixed
- Get user group permisssions
- getIdAttributeName() : string
- Return id column name dependiv of id value type for string return uuid
- getItemsQuery() : Builder
- Get relations
- getLastId() : int|null
- Get last id
- getLastRow() : Model|null
- Get last row
- getPermission() : Model|bool
- Return permission for user or group
- getRelatedItems() : Collection|null
- Get relations items
- getRelationAttributeName() : string|null
- Get relation attribute name
- getRelationModel() : Model|false
- Get relation
- getRelationModelClass() : string|null
- Get relation model class
- getRelationsQuery() : Builder
- Get relations query for model id
- getUserPermission() : Model|false
- Get user permission
- getUserPermissions() : mixed
- Get users permisssions
- hasAttribute() : bool
- Return true if atr exist
- hasFull() : bool
- Return true if have all permissions
- hasPermission() : bool
- Return true if have permission
- hasPermissions() : bool
- Check for permissions in current object
- hasRelatedItems() : bool
- Return true if related items > 0
- hasRelation() : bool
- Return true if relation exist
- permission() : Permissions
- Permissions model relation
- related() : mixed
- Morphed model
- relations() : Relation
- Relations
- removePermisionType() : bool
- Remove permission type
- resolvePermissions() : array<string|int, mixed>
- Resolve permissions array
- saveRelation() : Model|false
- Save relation
- saveRelations() : array<string|int, mixed>
- Save relations
- scopeSearchIgnoreCase() : Builder
- Case insensitive search
- setGroupPermission() : Model|bool
- Set group permisison
- setPermission() : Model|false
- Add or Update permission
- setUserPermission() : Model|bool
- Set user permission
- verifyPermissions() : bool
- Check for permissions
- whereIgnoreCase() : Builder
- Where case insensitive
Constants
GROUP
public
mixed
GROUP
= 'group'
USER
public
mixed
USER
= 'user'
Properties
$timestamps
Disable timestamps
public
bool
$timestamps
= false
$DEFAULT_UUID_COLUMN
Default uuid column name
protected
static string
$DEFAULT_UUID_COLUMN
= 'uuid'
$fillable
Fillable attributes
protected
array<string|int, mixed>
$fillable
= ['uuid', 'read', 'write', 'delete', 'execute', 'permission_id', 'relation_id', 'relation_type']
$relationColumnName
Reation column name
protected
string
$relationColumnName
= 'permission_id'
$relationModelClass
Relation model class
protected
string
$relationModelClass
= \Arikaim\Core\Models\Permissions::class
$table
Db table name
protected
string
$table
= 'permission_relations'
Methods
addPermisionType()
Add permission type
public
addPermisionType(string $permissionType[, string|null|int $id = null ]) : bool
Parameters
- $permissionType : string
- $id : string|null|int = null
Return values
booladdPermission()
Add permission item.
public
addPermission(string $name[, string|null $title = null ][, string|null $description = null ][, string|null $extension = null ][, bool|null $deny = false ]) : bool
Parameters
- $name : string
- $title : string|null = null
- $description : string|null = null
- $extension : string|null = null
- $deny : bool|null = false
Return values
boolbootUuid()
Init model events.
public
static bootUuid() : void
deletePermission()
Delete permission for user or group
public
deletePermission(string|int $name, int $id[, string $type = Self::USER ]) : bool
Parameters
- $name : string|int
-
Permission name, slug or id
- $id : int
- $type : string = Self::USER
Return values
booldeleteRelation()
Delete relation
public
deleteRelation([int|string|null $id = null ]) : bool
Parameters
- $id : int|string|null = null
Return values
booldeleteRelations()
Delete relations
public
deleteRelations(int|null $id[, string|null $type = null ][, int|null $relationId = null ]) : bool
Parameters
- $id : int|null
- $type : string|null = null
- $relationId : int|null = null
Return values
boolfindByColumn()
Find model by column name
public
findByColumn(mixed $value[, string|null|array<string|int, mixed> $column = null ]) : Model|null
Parameters
- $value : mixed
- $column : string|null|array<string|int, mixed> = null
Return values
Model|nullfindById()
Find model by id or uuid
public
findById(int|string $id) : Model|null
Parameters
- $id : int|string
Return values
Model|nullfindByIdQuery()
Return query builder
public
findByIdQuery(int|string $id) : Builder
Parameters
- $id : int|string
Return values
BuilderfindItems()
Find collection of models by id or uuid
public
findItems(array<string|int, mixed>|null $items) : QueryBuilder|false
Parameters
- $items : array<string|int, mixed>|null
Return values
QueryBuilder|falsefindMultiple()
Find multiole query
public
findMultiple(array<string|int, mixed> $idList) : Builder
Parameters
- $idList : array<string|int, mixed>
Return values
BuilderfindQuery()
Return query builder
public
findQuery(mixed $value[, string|null|array<string|int, mixed> $column = null ]) : Builder
Parameters
- $value : mixed
- $column : string|null|array<string|int, mixed> = null
Return values
BuildergetGroupPermission()
Get group permission
public
getGroupPermission(string $name, string|int $id) : Model|bool
Parameters
- $name : string
- $id : string|int
Return values
Model|boolgetGroupPermissions()
Get user group permisssions
public
getGroupPermissions(int $groupId) : mixed
Parameters
- $groupId : int
getIdAttributeName()
Return id column name dependiv of id value type for string return uuid
public
getIdAttributeName(int|string $id) : string
Parameters
- $id : int|string
Return values
stringgetItemsQuery()
Get relations
public
getItemsQuery(int|null $id[, string|null $type = null ]) : Builder
Parameters
- $id : int|null
- $type : string|null = null
Return values
BuildergetLastId()
Get last id
public
getLastId() : int|null
Return values
int|nullgetLastRow()
Get last row
public
getLastRow([string $field = 'id' ]) : Model|null
Parameters
- $field : string = 'id'
Return values
Model|nullgetPermission()
Return permission for user or group
public
getPermission(string|int $name, int $id[, string $type = Self::USER ]) : Model|bool
Parameters
- $name : string|int
-
Permission name, slug or id
- $id : int
- $type : string = Self::USER
Return values
Model|boolgetRelatedItems()
Get relations items
public
getRelatedItems(int|null $relationId[, string|null $type = null ]) : Collection|null
Parameters
- $relationId : int|null
- $type : string|null = null
Return values
Collection|nullgetRelationAttributeName()
Get relation attribute name
public
getRelationAttributeName() : string|null
Return values
string|nullgetRelationModel()
Get relation
public
getRelationModel(int|null $id, string|null $type, int|null $relationId) : Model|false
Parameters
- $id : int|null
- $type : string|null
- $relationId : int|null
Return values
Model|falsegetRelationModelClass()
Get relation model class
public
getRelationModelClass() : string|null
Return values
string|nullgetRelationsQuery()
Get relations query for model id
public
getRelationsQuery(int|null $relationId[, string|null $type = null ]) : Builder
Parameters
- $relationId : int|null
- $type : string|null = null
Return values
BuildergetUserPermission()
Get user permission
public
getUserPermission(string|int $name, int|string $userId) : Model|false
Parameters
- $name : string|int
-
Permission name, slug or id
- $userId : int|string
Return values
Model|falsegetUserPermissions()
Get users permisssions
public
getUserPermissions(int $userId) : mixed
Parameters
- $userId : int
hasAttribute()
Return true if atr exist
public
hasAttribute(string $attr) : bool
Parameters
- $attr : string
Return values
boolhasFull()
Return true if have all permissions
public
hasFull([bool $deny = false ]) : bool
Parameters
- $deny : bool = false
Return values
boolhasPermission()
Return true if have permission
public
hasPermission(string $name[, bool $deny = false ]) : bool
Parameters
- $name : string
-
valid values read|write|delete|execute
- $deny : bool = false
Return values
boolhasPermissions()
Check for permissions in current object
public
hasPermissions(mixed $name, mixed $userId, array<string|int, mixed> $permissions[, bool $deny = false ]) : bool
Parameters
- $name : mixed
- $userId : mixed
- $permissions : array<string|int, mixed>
- $deny : bool = false
Return values
boolhasRelatedItems()
Return true if related items > 0
public
hasRelatedItems(int|null $id[, string|null $type = null ]) : bool
Parameters
- $id : int|null
- $type : string|null = null
Return values
boolhasRelation()
Return true if relation exist
public
hasRelation(int|null $id, string|null $type, int|null $relationId) : bool
Parameters
- $id : int|null
- $type : string|null
- $relationId : int|null
Return values
boolpermission()
Permissions model relation
public
permission() : Permissions
Return values
Permissionsrelated()
Morphed model
public
related([string|null $type = null ]) : mixed
Parameters
- $type : string|null = null
relations()
Relations
public
relations() : Relation
Return values
RelationremovePermisionType()
Remove permission type
public
removePermisionType(string $permissionType[, string|null|int $id = null ]) : bool
Parameters
- $permissionType : string
- $id : string|null|int = null
Return values
boolresolvePermissions()
Resolve permissions array
public
resolvePermissions(array<string|int, mixed>|string $access) : array<string|int, mixed>
Parameters
- $access : array<string|int, mixed>|string
Return values
array<string|int, mixed>saveRelation()
Save relation
public
saveRelation(int|null $id, string|null $type, int|null $relationId) : Model|false
Parameters
- $id : int|null
- $type : string|null
- $relationId : int|null
Return values
Model|falsesaveRelations()
Save relations
public
saveRelations(array<string|int, mixed> $items, string|null $type, int|null $relationId) : array<string|int, mixed>
Parameters
- $items : array<string|int, mixed>
- $type : string|null
- $relationId : int|null
Return values
array<string|int, mixed>scopeSearchIgnoreCase()
Case insensitive search
public
scopeSearchIgnoreCase(Builder $query, string $column, string|null $value) : Builder
Parameters
- $query : Builder
- $column : string
- $value : string|null
Return values
BuildersetGroupPermission()
Set group permisison
public
setGroupPermission(string $name, array<string|int, mixed> $permissions, int|string $id) : Model|bool
Parameters
- $name : string
-
Permission Name Or Slug
- $permissions : array<string|int, mixed>
- $id : int|string
-
Group Id, Uuid or Slug
Return values
Model|boolsetPermission()
Add or Update permission
public
setPermission(string|int $name, array<string|int, mixed> $access, int $id[, int $type = Self::USER ]) : Model|false
Parameters
- $name : string|int
- $access : array<string|int, mixed>
-
- ['read','write','delete','execute]
- $id : int
-
user Id or group Id
- $type : int = Self::USER
Return values
Model|falsesetUserPermission()
Set user permission
public
setUserPermission(string $name, array<string|int, mixed> $permissions[, int|string|null $id = null ]) : Model|bool
Parameters
- $name : string
- $permissions : array<string|int, mixed>
- $id : int|string|null = null
Return values
Model|boolverifyPermissions()
Check for permissions
public
verifyPermissions(array<string|int, mixed> $permissions[, bool $deny = false ]) : bool
Parameters
- $permissions : array<string|int, mixed>
- $deny : bool = false
Return values
boolwhereIgnoreCase()
Where case insensitive
public
whereIgnoreCase(string $attribute, mixed $value[, string $operator = '=' ]) : Builder
Parameters
- $attribute : string
- $value : mixed
- $operator : string = '='