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

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

mniknab/entrust
===============

This package provides a flexible way to add role-based permissions to Laravel and is a fork from jromero98/entrust - Now support laravel 9

3.1(4y ago)0482MITPHPPHP &gt;=8.0

Since Nov 10Pushed 4y agoCompare

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

READMEChangelog (2)Dependencies (5)Versions (13)Used By (0)

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

[](#entrust-laravel-package)

[![Latest Stable Version](https://camo.githubusercontent.com/d0ba146be1764778b07794a77d92abb80b3189698daf5860cf979c3deb926f31/68747470733a2f2f706f7365722e707567782e6f72672f6d6e696b6e61622f656e74727573742f762f737461626c653f666f726d61743d706c6173746963)](https://packagist.org/packages/mniknab/entrust)

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

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 Entrust, just run:

```
composer require mniknab/entrust
```

If your version is laravel 8

```
composer require mniknab/entrust:2.0
```

If your version is laravel 7

```
composer require mniknab/entrust:1.0.2
```

If your version is laravel 6

```
composer require mniknab/entrust:0.6
```

If your version is laravel 5.8

```
composer require mniknab/entrust:0.2
```

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

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

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

```
php artisan vendor:publish
```

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

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

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

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

```
