bigfive-edition / laravel-bfe-permission
A library for big five to manage permissions
Requires
- php: ^8.0|^8.1
- astrotomic/laravel-translatable: ^11.12
- illuminate/auth: ^7.0|^8.0|^9.0|^10.0
- illuminate/container: ^7.0|^8.0|^9.0|^10.0
- illuminate/contracts: ^7.0|^8.0|^9.0|^10.0
- illuminate/database: ^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^7.0|^8.0|^9.0|^10.0
- prettus/l5-repository: ^2.9
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.4
- predis/predis: ^1.1
- dev-main
- 1.0.46
- 1.0.45
- 1.0.44
- 1.0.43
- 1.0.42
- 1.0.41
- 1.0.40
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-repos
This package is not auto-updated.
Last update: 2025-03-04 01:48:18 UTC
README
Documentation, Installation, and Usage Instructions
To get started with using the package, we'll install it using the following command:
add the private repository in your composer.json file
"repositories": [ { "type": "vcs", "url": "git@gitlab.bfedition.com:bigcity/bigcity-instances/bigfiveedition-laravel-permission.git" } ],
composer require bigfive-edition/laravel-bfe-permission
Now that we've installed the package, we'll need to publish the database migration and config file:
php artisan bfe-permission:install
We can now run the migrations to create the new tables in our database:
php artisan migrate
Assuming that we are using the default config values and haven't changed anything in the package's config/bfe-permission.php, we should now have five new tables in our database:
We can also generate the default
php artisan bfe-permission:generate-teams php artisan bfe-permission:generate-roles php artisan bfe-permission:generate-abilities
Http Routes
it comes with default routes for managing team, roles, and abilities check the postman collection
{routes_prefix}/bfe-permissions/teams
{routes_prefix}/bfe-permissions/teams/{team_id}/models
{routes_prefix}/bfe-permissions/roles
{routes_prefix}/bfe-permissions/roles/{role_id}/models
{routes_prefix}/bfe-permissions/abilities
{routes_prefix}/bfe-permissions/abilities/{ability_id}/models
Http Route Middlewares
Adding routes middlewares as follow.
Note that the |
is for OR operations and the &
is for AND operations
bfe-permission.teams:waiters|managers
bfe-permission.teams:waiters&managers
bfe-permission.roles:admin|system_admin
bfe-permission.roles:admin&system_admin
bfe-permission.abilities:read_all_users|create_one_vehicle
bfe-permission.abilities:read_all_users&create_one_vehicle
bfe-permission.abilities:read_all_users|create_one_vehicle,{resource_class},{resource_id}
bfe-permission.abilities:read_all_users&create_one_vehicle,{resource_class},{resource_id}
Gates and Policies [refer to https://laravel.com/docs/9.x/authorization]
Here are the predefined abilities beside the ones autogenerated and managed by admin in bfe_permission_abilities
table
bfe-permission-belongs-teams
: checks if the user belongs to passed teams
Gate::allows('bfe-permission-belongs-teams', 'admin')
Gate::forUser($user)->allows('bfe-permission-belongs-teams', 'admin | manager')
Gate::forUser($user)->allows('bfe-permission-belongs-teams', 'admin & manager')
bfe-permission-has-roles
: checks if the user has passed roles
Gate::allows('bfe-permission-has-roles', 'admin')
Gate::forUser($user)->allows('bfe-permission-has-roles', 'admin | waiter')
Gate::forUser($user)->allows('bfe-permission-has-roles', 'admin & waiter')
bfe-permission-has-abilities
: checks if the user has passed abilities on passed resource
Gate::allows('bfe-permission-has-abilities', 'create_user')
Gate::forUser($user)->allows('bfe-permission-has-abilities', 'create_user | delete_user')
Gate::forUser($user)->allows('bfe-permission-has-abilities', 'create_user & delete_user')
Gate::forUser($user)->allows('bfe-permission-has-abilities', ['create_user | delete_user', $resourceObject])
Gate::forUser($user)->allows('bfe-permission-has-abilities', ['create_user & delete_user', $resourceObject])
ability-name
: checks if the user has ability on passed resource
Gate::allows('ability-name')
Gate::forUser($user)->allows('ability-name', $resourceObject)