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

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

sunergix/entrust-permissions
============================

This package provides a flexible way to add role-based permissions to Laravel 12 and 13.

v6.0(1mo ago)125.0k↑179.2%1[1 PRs](https://github.com/sunergix/entrust-permissions/pulls)MITPHPPHP ^8.3

Since Feb 7Pushed 1mo agoCompare

[ Source](https://github.com/sunergix/entrust-permissions)[ Packagist](https://packagist.org/packages/sunergix/entrust-permissions)[ RSS](/packages/sunergix-entrust-permissions/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)Dependencies (14)Versions (38)Used By (0)

ENTRUST (Laravel 12|13 Package)
===============================

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

Forked from [zizaco/entrust](https://github.com/Zizaco/entrust)

Entrust is a succinct and flexible way to add role-based permissions to **Laravel 12|13**.

If you are using an older version of laravel, use version ~3.0

Contents
--------

[](#contents)

- [ENTRUST (Laravel 12|13 Package)](#entrust-laravel-1213-package)
    - [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)
    - [Troubleshooting](#troubleshooting)
    - [License](#license)
    - [Contribution guidelines](#contribution-guidelines)

Installation
------------

[](#installation)

1. Install the package with Composer:

```
composer require sunergix/entrust-permissions
```

2. Laravel package discovery registers the service provider and facade automatically. If your application disables package discovery, add the service provider manually:

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

3. If needed, add the facade alias manually:

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

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

```
php artisan vendor:publish --tag=entrust-config
```

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), register aliases in your bootstrap middleware configuration:

```
    'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
    'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
    'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
```

For Laravel 12 and 13, register aliases with `bootstrap/app.php` middleware configuration.

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:

```
