2017 © Pedro Peláez
 

laravel-package role-manager

Laravel Role And Permission Manager

image

mamikon/role-manager

Laravel Role And Permission Manager

  • Monday, April 17, 2017
  • by mamikon1
  • Repository
  • 0 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

RoleManager

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Role and permission management system for laravel. This package impalement Role Management in Laravel. And you can create in easy way new permissions and assign them to the roles., (*2)

Install

Via Composer, (*3)

``` bash $ composer require mamikon/role-manager, (*4)

Then  add the ServiceProvider to the providers array in `config/app.php`.

```php

Mamikon\RoleManager\RoleManagerProvider::class,

You can use the facade for shorter code. Add this to your aliases:, (*5)


'RoleManager' => Mamikon\RoleManager\RoleManagerFacade::class,

To publish the config settings use:, (*6)


$ php artisan vendor:publish --provider="Mamikon\RoleManager\RoleManagerProvider"

It will publish default views for Role and permission management and roleManager.php config file., (*7)

Before starting lets go over config file and make some configurations., (*8)

Config file contain default permissions, roles., (*9)

It will create some permissions for RoleManager package, after publishing package you can add some new permissions right there and it will be more preferable than from admin panel, it will make your application more easy shippable. Each permission must contain array key, it will be name of permission, and value of that key must be an array which contain description. in addition of this you can add class and method that will make additional checking for that permission, (*10)

'edit_post' => [
    'description' => "Edit Post",
    'class' => App\Permissions\Post::class, // not required
    'method' => 'canEdit', // not required
],

Then You can create default roles. Each array element must contain key which will be role name, and value- that will be description of our role, (*11)

'super-admin' =>  "Can Do everything",

Then You can assign some permissions to roles., (*12)

'assignPermissionsToRole'=> [
    'editor' => [
            'edit_post',
            'publish_post',
            //...
        ]
 ],

You can use asterisk for add all permissions to that role, (*13)

```php 'assignPermissionsToRole'=> [ 'super-admin' => '*' ],, (*14)


Then you can add roles to users ```php 'assignRoleToUser' => [ 'super-admin'=>'admin@pass.com', 'editor'=>'editor@pass.com', ],

All this configurations will be loaded after run artisan command permission:migrate, (*15)

$ php artisan permissions:migrate

But before that we must migrate our tables. It by default will create 4 tables * permissions * roles * roles_user * permissions_roles, (*16)

If in your database exist tables permissions, and roles you can change their names from config file and then migrate, (*17)

    'permissionsTable'=>'other_permissions',
    'rolesTable'=>'other_roles',

RoleManager package will create routes for Role management control pages * / * /role(resource) * /permission(resource) * /user/{id}, (*18)

And they will be prefixed by default with role-manager., (*19)

'routePrefix'=>'role-manager',

By default views will be extend form layouts.app, (*20)

'extendedView'=>'layouts.app',

If you don't want extend any view you can give value false And You must give section where must be extended, (*21)


'extendedSection'=>'content',

All configurations except default roles, permissions and default assignments can be loaded from .env, (*22)

ROLE_MANAGER_PERMISSIONS_TABLE=permissions
ROLE_MANAGER_ROLES_TABLE=roles
ROLE_MANAGER_EXTENDED_VIEW=layout.app
ROLE_MANAGER_EXTENDED_SECTION=content
ROLE_MANAGER_EXTERNAL_BOOTSTRAP=false
ROLE_MANAGER_EXTERNAL_JQUERY=false
ROLE_MANAGER_ROUTE_PREFIX=role-manager
USERS_PER_PAGE=15
PERMISSIONS_PER_PAGE=15
ROLES_PER_PAGE=15

After all configuration will done run migration, (*23)

$ php aritsan migrate

And then, (*24)

$ php aritsan permissions:migrate

Usage

RoleManager don't change any logic in laravel authorization. You can use standard laravel facades, methods and functions., (*25)

if (Gate::allows('update-post', $post)) {
    // The current user can update the post...
}

if (Gate::denies('update-post', $post)) {
    // The current user can't update the post...
}

In addition RoleManager facade has 2 helper functions * RoleManager::assignRole(mixed $user, mixed $role) * RoleManager::removeRole(mixed $user, mixed $role), (*26)

As $user parameter can be User Model, or user_id(int) As $role parameter can be Role Model, role_id(int), or role name(string), (*27)

Change log

Please see CHANGELOG for more information on what has changed recently., (*28)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*29)

Security

If you discover any security related issues, please email m.araqelyan@gmail.com instead of using the issue tracker., (*30)

Credits

License

The MIT License (MIT). Please see License File for more information., (*31)

The Versions

17/04 2017

dev-master

9999999-dev

Laravel Role And Permission Manager

  Sources   Download

MIT

The Requires

 

by Mamikon Arakelyan

laravel role permission

13/04 2017

1.0.5

1.0.5.0

Laravel Role And Permission Manager

  Sources   Download

MIT

The Requires

 

by Mamikon Arakelyan

laravel role permission

13/04 2017

1.0.2

1.0.2.0

Laravel Role And Permission Manager

  Sources   Download

MIT

The Requires

 

by Mamikon Arakelyan

laravel role permission

13/04 2017

1.0.1

1.0.1.0

Laravel Role And Permission Manager

  Sources   Download

MIT

The Requires

 

by Mamikon Arakelyan

laravel role permission

13/04 2017

1.0.0

1.0.0.0

Laravel Role And Permission Manager

  Sources   Download

MIT

The Requires

 

by Mamikon Arakelyan

laravel role permission