A permission management system to handel the user role in a Laravel 5 project.
This package is only installed via composer by requiring the
composer require binssoft/permissionmanager
package in your project's composer.json
. (The installation may take a while.)
{
"require": {
"binssoft/permissionmanager": "<version-name>"
}
}
Next, add the service provider to config/app.php
.
'providers' => [
...
Binssoft\Permissionmanager\PermissionManagerServiceProvider::class
]
'aliases' => [
...
'Permission'=> Binssoft\Permissionmanager\PermissionManager::class
]
php artisan vendor:publish
php artisan migrate
After proper vendor publish few files are created and 4 tables will be created in the configured database after migration.
-
in
app/
folder 4 models will generatedRoles.php
,Navigations.php
,UserRoles.php
,RolePermissions.php
-
in
database\seeds
folderRoleSeeder.php
will be created
php artisan db:seed --class=RoleSeeder
Few demo role records will be inserted in the roles
Table
use Permission;
Permission::assignUserRole(<user_id>,<role_id>);
Permission::getUserRole(<user_id>);
Permission::navigations(['namespace'=>["admin"]]);
namespace will be a array with value of your different namespaces like admin,site etc.
- 1st parameter : role id
- 2nd parameter : route name
- 3rd parameter : want to save or delete (true/false)
Permission::setRolePermission(1, 'admin_user_list', true);
$permission = Permission::access(<role_id>);
$permission
will return true
or flase
Please click on "Star" in github if it is usefull for you.