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

Abandoned → [zizaco/entrust](/?search=zizaco%2Fentrust)Library[Authentication &amp; Authorization](/categories/authentication)

michele-angioni/entrust
=======================

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

1.7.0(10y ago)134192MITPHPPHP &gt;=5.5.0

Since Feb 7Pushed 9y ago2 watchersCompare

[ Source](https://github.com/micheleangioni/entrust)[ Packagist](https://packagist.org/packages/michele-angioni/entrust)[ RSS](/packages/michele-angioni-entrust/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (26)Used By (0)

ENTRUST (Laravel 5 Package)
===========================

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

[![Build Status](https://camo.githubusercontent.com/f0dd3d7b1fb8d7d7fe73a6fc644e1fd7a5c3d457734afbdce0e0ebccda234434/68747470733a2f2f7472617669732d63692e6f72672f5a697a61636f2f656e74727573742e737667)](https://travis-ci.org/Zizaco/entrust)[![Version](https://camo.githubusercontent.com/bba6a1ab9744aab3aaffd52c220871a8a51e8187f67d650f3dec9d834aac868f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f5a697a61636f2f656e74727573742e737667)](https://packagist.org/packages/zizaco/entrust)[![License](https://camo.githubusercontent.com/7254c1d715cc83039b0c4b02b58db99a82939ffdbc87652edac27fa984ceb4fa/68747470733a2f2f706f7365722e707567782e6f72672f7a697a61636f2f656e74727573742f6c6963656e73652e737667)](https://packagist.org/packages/zizaco/entrust)[![Total Downloads](https://camo.githubusercontent.com/9c2d0cdabee70745d07651a3c50ace28064e157c35055b6e6ad01bc41b16803d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a697a61636f2f656e74727573742e737667)](https://packagist.org/packages/zizaco/entrust)

[![SensioLabsInsight](https://camo.githubusercontent.com/0b1aa6bf92e58c3ebf1d5d2737f62dbbdc9b0f1f39190beb44d508e54933a386/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63633461663936362d383039622d346662632d623862322d6262323835306536373131652f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/cc4af966-809b-4fbc-b8b2-bb2850e6711e)

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/Zizaco/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)

In order to install Laravel 5 Entrust, just add

```
"zizaco/entrust": "5.2.x-dev"

```

to your composer.json. Then run `composer install` or `composer update`.

Then in your `config/app.php` add

```
    Zizaco\Entrust\EntrustServiceProvider::class,
```

in the `providers` array and

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

to the `aliases` array.

If you are going to use [Middleware](#middleware) (requires Laravel 5.1 or later) you also need to add

```
    '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.

You can also publish the configuration for this package to further customize table names and model namespaces.
Just use `php artisan vendor:publish` and a `entrust.php` file will be created in your app/config directory.

### 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:

```
