PHPackages                             scolib/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. scolib/entrust

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

scolib/entrust
==============

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

v2.1.2(8y ago)0871MITPHPPHP &gt;=7.0.0

Since Feb 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ScoLib/entrust)[ Packagist](https://packagist.org/packages/scolib/entrust)[ RSS](/packages/scolib-entrust/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (7)Versions (30)Used By (0)

ENTRUST (Laravel 5.\* Package)
==============================

[](#entrust-laravel-5-package)

[![StyleCI](https://camo.githubusercontent.com/72c4bc9fc77a0ca97a0ee18c6d17b000d5a4c50a9880f0807e46b8951054deba/68747470733a2f2f7374796c6563692e696f2f7265706f732f38343032333739372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/84023797)[![Build Status](https://camo.githubusercontent.com/d48e9d70baedf67aea514bd55608cfbcb3bc72765df7b19524d8b9b5c3eee777/68747470733a2f2f7472617669732d63692e6f72672f53636f4c69622f656e74727573742e737667)](https://travis-ci.org/ScoLib/entrust)[![Version](https://camo.githubusercontent.com/05598ba808bd619eed5cb52bb1c149d76987991a73a5c045a7436fc246826f7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73636f6c69622f656e74727573742e737667)](https://packagist.org/packages/scolib/entrust)[![License](https://camo.githubusercontent.com/1774edac0065c2ad3bfa7faadf1157b8c06a5ce19a0fa460fcf4bd5fbae7af7b/68747470733a2f2f706f7365722e707567782e6f72672f73636f6c69622f656e74727573742f6c6963656e73652e737667)](https://packagist.org/packages/scolib/entrust)[![Total Downloads](https://camo.githubusercontent.com/77748f267746d71857551776d062fdf7e9cf5815dc39c2fb5cc0258342dda18b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73636f6c69622f656e74727573742e737667)](https://packagist.org/packages/scolib/entrust)

Entrust is a succinct and flexible way to add Role-based Permissions to **Laravel 5.**\*.

If you are looking for the Laravel 4 version, take a look [Branch 1.0](https://github.com/ScoLib/entrust/tree/1.0). It contains the latest entrust version for Laravel 4.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Configuration](#configuration)
    - [User relation to roles](#user-relation-to-roles)
    - [Models](#models)
        - [Role](#role)
        - [Permission](#permission)
        - [User](#user)
        - [Soft Deleting](#soft-deleting)
- [Usage](#usage)
    - [Concepts](#concepts)
        - [Checking for Roles &amp; Permissions](#checking-for-roles--permissions)
        - [User ability](#user-ability)
    - [Blade templates](#blade-templates)
    - [Middleware](#middleware)
    - [Short syntax route filter](#short-syntax-route-filter)
    - [Route filter](#route-filter)
- [Troubleshooting](#troubleshooting)
- [License](#license)
- [Contribution guidelines](#contribution-guidelines)
- [Additional information](#additional-information)

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

[](#installation)

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

```
"scolib/entrust": "2.1.*"
```

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

```
php artisan vendor:publish
```

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

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

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

```
    'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
    'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
    'ability' => \Zizaco\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:

```
