PHPackages                             klaravel/ntrust - 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. klaravel/ntrust

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

klaravel/ntrust
===============

Role-Based Permissions for Laravel 5.3+

v1.1.7(8y ago)10126.7k25[1 issues](https://github.com/klaravel/ntrust/issues)[1 PRs](https://github.com/klaravel/ntrust/pulls)1MITPHP

Since Oct 3Pushed 4y ago13 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (15)Used By (1)

NTRUST Multi-User Roles &amp; Permissions (Laravel 5.4)
-------------------------------------------------------

[](#ntrust-multi-user-roles--permissions-laravel-54)

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

**Original 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)
    - [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)

In order to install Laravel 5 Ntrust, just add

```
"klaravel/ntrust": "1.1.*"

```

to your composer.json. Then run `composer install` or `composer update`.

or you can run the `composer require` command from your terminal:

```
composer require klaravel/ntrust

```

Then in your `config/app.php` add

```
Klaravel\Ntrust\NtrustServiceProvider::class,
```

in the `providers` array and

```
'Ntrust' => Klaravel\Ntrust\NtrustFacade::class,
```

to the `aliases` array.

If you are going to use [Middleware](#middleware) (requires Laravel 5.1 or later) you also need to add

```
'role' => \Klaravel\Ntrust\Middleware\NtrustRole::class,
'permission' => \Klaravel\Ntrust\Middleware\NtrustPermission::class,
'ability' => \Klaravel\Ntrust\Middleware\NtrustAbility::class,
```

to `routeMiddleware` array in `app/Http/Kernel.php`.

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

[](#configuration)

Just use `php artisan vendor:publish` and a `ntrust.php` file will be created in your app/config directory.

See that file to get more detail like how to add multiple users. Default we added two users example like normal `user` and `admin`.

### User relation to roles

[](#user-relation-to-roles)

Now generate the Ntrust migration:

```
php artisan ntrust:migration {name}
```

Profile `{name}` name of profile which you have in file `config/ntrust.php` section `profiles`.

It will generate the `__ntrust_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 like below or whatever you have entered table name in `config/ntrust.php` configuration file.

- `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/Role.php` using the following example:

```
