Download the PHP package nh/access-control without Composer
On this page you can find all versions of the php package nh/access-control. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nh/access-control
More information about nh/access-control
Files in nh/access-control
Package access-control
Short Description Access controle via roles and permissions
License MIT
Informations about the package access-control
Installation
Install the package via composer:
Publish the databases and the models for the roles:
To make a model with role, you can create a migration via the console commande: The --many option will create a roleables table with many to many morph relationship
Then, if your model is has only one role add the HasAccess trait to your model:
Create permission
You can create permission via the console commande: You can create a single permission, or all action permissions for a model.
Check the access
Check if a model has any role :
Check if a model has some roles : You must pass a string or an array By default it will check on the guard column, but you can specify the column
Check if a model has some permissions : You must pass a string or an array
Check if a model has access to a model/action : You must pass a string for the model and a string or an array for the actions
Check if a model has superpower : You can change the superpowers role in the config file
Scope the model with role(s) :
Models
The package come with two models:
- Role
- Permission
Role
The role have a guard and name attribute.
You can retrieve the restricted permissions:
You can also retrieve the restricted permissions from a model with multiple roles:
You can check if a role have a permission: $permissions can be a string or an array
You can check if a role have a permission by model/action: $actions can be a string or an array $strict must be a boolean, and check if AS ANY or AS ALL permission
Events
You can use the RoleEvent for dispatch events that happen to the role access.
You can use the PermissionEvent for dispatch events that happen to the role/permission access.
Gates
You can use the set-roles Gate to check if current Auth can set the roles. $roles must be an array of ids In the config file you can specify the roles that are guarded and required an Auth of the same role
You can use the set-permissions Gate to check if current Auth can set the permission for a role. $permissions must be an array of ids In the config file you can specify the roles that are guarded and required an Auth of the same role