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

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

pdeio/entrust
=============

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

2.0.1(7y ago)032MITPHPPHP &gt;=5.5.0

Since Feb 7Pushed 7y ago1 watchersCompare

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

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

ENTRUST (Laravel 5.8 Package)
=============================

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

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

My fork is intended to:

Adapt the entrust package to an API backend app;

Update migration tables to work with the new laravel users migration table;

To create the option to have a superuser without any permissions / roles, but that can manage all the permissions and functions of the ACL;

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)
    - [Super Admin](#admin)
    - [Concepts](#concepts)
        - [Checking for Roles &amp; Permissions](#checking-for-roles--permissions)
        - [User ability](#user-ability)
    - [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, just run:

```
composer require pdeio/entrust
```

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

```
php artisan vendor:publish --provider "Pdeio\Entrust\EntrustServiceProvider"
```

3. 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',
    ],
],
```

4. If you want to use [Middleware](#middleware) you also need to add the following:

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

Run tables migrations with the artisan migrate command:

```
php artisan migrate
```

\*Remember, if you use the MYSQL database, define in your `users` table the same engine as the entrust tables. The `MyISAM` engine pattern does not support foreign keys. If you have already created the `users` table, modify the structure table.

```
    ...
    $table->engine = "InnoDB";
    ...
```

After the migration, four new tables will be present:

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

### Models

[](#models)

#### Role

[](#role)

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

```
