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

ActiveLibrary

vildanbina/laravel-entrust
==========================

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

04PHP

Since Jan 22Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

[![Build Status](https://camo.githubusercontent.com/925957b33fe3f1bb0458f1ffa63efbed498540b6c6adc942ecc1c8efec8a313e/68747470733a2f2f7472617669732d63692e6f72672f76696c64616e62696e612f656e74727573742e737667)](https://travis-ci.org/vildanbina/entrust)[![Version](https://camo.githubusercontent.com/13793d4da9a9f2cd1abba74d49115955e43235ba1a562cbd293d3a5de00e4f84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76696c64616e62696e612f656e74727573742e737667)](https://packagist.org/packages/vildanbina/entrust)[![License](https://camo.githubusercontent.com/489da8077a394db63ecc47d26d2bb17c2d0531ace0f965ed254ea5dc37391460/68747470733a2f2f706f7365722e707567782e6f72672f76696c64616e62696e612f656e74727573742f6c6963656e73652e737667)](https://packagist.org/packages/vildanbina/entrust)[![Total Downloads](https://camo.githubusercontent.com/b2444da5de04b3c9c0021298b239218f48149c178016db86c3dd0cd11f6ae08d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76696c64616e62696e612f656e74727573742e737667)](https://packagist.org/packages/vildanbina/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/vildanbina/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 Entrust, just add the following to your composer.json. Then run `composer update`:

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

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

```
vildanbina\Entrust\EntrustServiceProvider::class,
```

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

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

```
