PHPackages                             lichv/entrust - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. lichv/entrust

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

lichv/entrust
=============

This package provides a flexible way to add Role-based Permissions to Laravel

v0.1.0(7y ago)115MITPHPPHP &gt;=5.5.0

Since Dec 19Pushed 7y ago1 watchersCompare

[ Source](https://github.com/lichv/entrust)[ Packagist](https://packagist.org/packages/lichv/entrust)[ RSS](/packages/lichv-entrust/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

entrust
=======

[](#entrust)

Role-based Permissions for Laravel 5

fork 扩展RBAC，添加用户分组部分，用户和用户分组同事具有角色，多对多关系，分组可用于部门管理或团队管理

Installation
------------

[](#installation)

1. In order to install Laravel 5 Entrust, just add the following to your composer.json. Then run `composer update`:

```
"lichv/entrust": "^0.2"
```

2. Open your `config/app.php` and add the following to the `providers` array:

```
Lichv\Entrust\EntrustServiceProvider::class,
```

3. In the same `config/app.php` and add the following to the `aliases ` array:

```
'Entrust'   => Lichv\Entrust\EntrustFacade::class,
```

4. Run the command below to publish the package config file `config/entrust.php`:

```
php artisan vendor:publish
```

5. Open your `config/auth.php` and add the following to it:

```
'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => Namespace\Of\Your\User\Model\User::class,
        'table' => 'users',
    ],
],
```

6. If you want to use [Middleware](#middleware) (requires Laravel 5.1 or later) you also need to add the following:

```
    'role' => \Lichv\Entrust\Middleware\EntrustRole::class,
    'permission' => \Lichv\Entrust\Middleware\EntrustPermission::class,
    'ability' => \Lichv\Entrust\Middleware\EntrustAbility::class,
```

to `routeMiddleware` array in `app/Http/Kernel.php`.

Configuration
-------------

[](#configuration)

Set the property values in the `config/auth.php`. These values will be used by entrust to refer to the correct user table and model.

To further customize table names and model namespaces, edit the `config/entrust.php`.

### User relation to roles

[](#user-relation-to-roles)

Now generate the Entrust migration:

```
php artisan entrust:migration
```

It will generate the `_entrust_setup_tables.php` migration. You may now run it with the artisan migrate command:

```
php artisan migrate
```

After the migration, four new tables will be present:

- `roles` — stores role records
- `permissions` — stores permission records
- `role_user` — stores [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) relations between roles and users
- `permission_role` — stores [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) relations between roles and permissions

### Models

[](#models)

#### Role

[](#role)

Create a Role model inside `app/models/Role.php` using the following example:

```
