-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Permissions-handler is an easy-to-use package for laravel 5 to manage users roles and permissions based on Doctrine Annotations.
use PermissionsHandler\Owns;
use PermissionsHandler\Roles;
use PermissionsHandler\Permissions;
.
.
.
/**
* @Permissions({"add-posts"})
*/
function store(Request $request) {
// your code here
}
/**
* @Roles({"admin"})
*/
function delete(Request $request) {
// your code here
}
/**
* @Owns(relation="posts", parameter="id")
*/
function update(Request $request) {
// your code here
}
As the above example, Permissions Handler comes with three types of annotations.
-
Permissions({"perm1"})
:
only users that have perm1 permission can access this method -
Roles({"role1"})
:
only users that have role1 role can access this method -
Owns(relation="posts", parameter="id")
:
for example, if you are the owner of the post then only you whose can edit this post.Owns
will ensure that, just pass the relation and the parameter which PermissionsHandler will get the value from the Request accordingly.
Check the usage section for more features and details
Permissions Handler uses the caching feature on two levels
-
Database Cache:
Permissions Handler uses the cache driver that configured in yourcache.php
file for caching user permissions, roles for configurable time. -
Annotation Cache:
Because of parsing the files against the annotations is costy; permission Hander caches the parsed annotations to avoid parsing it again. by default this features is disabled in the development environment and enabled in the production.
Gate Integration
PermissionsHandler register users permissions into the Gate
, so you can easly use laravel built in can
method.
PermissionsHandler doesn't depend on a specific model or guard, you can use whatever models or guards you need, PermissionsHandler will handle all.
If you enabled the seeder
option from the config/permissionsHandler.php
file then Permissions Handler will save each created permission, role and role-permissions to fils to be able to seed it again in later time or share them with others.