PHPackages                             bbatsche/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. [Database &amp; ORM](/categories/database)
4. /
5. bbatsche/entrust

ActiveLibrary[Database &amp; ORM](/categories/database)

bbatsche/entrust
================

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

2.1.1(10y ago)41.3k4[6 issues](https://github.com/bbatsche/entrust/issues)MITPHPPHP &gt;=5.4.0

Since Feb 7Pushed 10y ago2 watchersCompare

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

READMEChangelogDependencies (8)Versions (27)Used By (0)

Entrust (Laravel4 Package)
==========================

[](#entrust-laravel4-package)

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

First and foremost I must give credit to the original developers of this package. Andrew Elkins (@andrewelkins) and Leroy Merlin (@zizaco) did excellent work on the fundamental design and functionality. My fork is intended to:

- Remove extra components not really relevant to role &amp; permission management (in particular, Ardent).
- Add extra functionality I felt was useful and particularly suited to this package.
- Make integrating the package more flexible and dynamic (eventually).

Were my changes ever to be integrated back into the Zizaco version of this plugin, I think that would be lovely. Either way though, I hope to demonstrate some genuinely helpful features and options.

Contents
--------

[](#contents)

- [Quick start](#quick-start)
    - [Required setup](#required-setup)
- [Configuration](#configuration)
    - [User Relation to Roles](#user-relation-to-roles)
    - [Models](#models)
        - [Role](#role)
        - [Permission](#permission)
        - [User](#user)
        - [Non-Standard Table Names](#non-standard-table-names)
            - [Role Constructor](#role-constructor)
            - [Permission Constructor](#permission-constructor)
        - [EntrustRole and EntrustPermission Classes](#entrustrole-and-entrustpermission-classes)
        - [Soft Deleting](#soft-deleting)
- [Usage](#usage)
    - [Concepts](#concepts)
        - [Checking for Roles &amp; Permissions](#checking-for-roles--permissions)
        - [User Ability](#user-ability)
    - [Controller Trait (and Filters)](#controller-trait)
    - [Short Syntax Route Filter](#short-syntax-route-filter)
    - [Route Filter](#route-filter)
- [Troubleshooting](#troubleshooting)
- [License](#license)
- [Additional Information](#additional-information)

Quick start
-----------

[](#quick-start)

**PS:** Even though it's not needed, Entrust works very well with [Confide](https://github.com/Zizaco/confide) in order to eliminate repetitive tasks involving the management of users: account creation, login, logout, confirmation by e-mail, password reset, etc.

[Take a look at Confide](https://github.com/Zizaco/confide).

### Required setup

[](#required-setup)

In the `require` key of `composer.json` file add the following:

```
"bbatsche/entrust": "~2.0"
```

Run the Composer update command:

```
composer update
```

In your `config/app.php` add `'Bbatsche\Entrust\EntrustServiceProvider'` to the end of the `$providers` array:

```
'providers' => array(
    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    // ...
    'Bbatsche\Entrust\EntrustServiceProvider',
),
```

At the end of `config/app.php` add `'Entrust' => 'Bbatsche\Entrust\EntrustFacade'` to the `$aliases` array:

```
'aliases' => array(
    'App'        => 'Illuminate\Support\Facades\App',
    'Artisan'    => 'Illuminate\Support\Facades\Artisan',
    // ...
    'Entrust'    => 'Bbatsche\Entrust\EntrustFacade',
),
```

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

[](#configuration)

Set the property values in the `config/auth.php` (typically, these values are configured correctly out of the box but it is worth double checking). 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:

```
php artisan config:publish bbatsche/entrust
```

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

```
