PHPackages                             xdroidteam/xtrust - 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. xdroidteam/xtrust

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

xdroidteam/xtrust
=================

Role and permission based rights for laravel

1.0.7(3mo ago)48.6k—0%MITPHPCI failing

Since Oct 15Pushed 3mo agoCompare

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

READMEChangelog (6)Dependencies (3)Versions (45)Used By (0)

Laravel permission, role based rights
=====================================

[](#laravel-permission-role-based-rights)

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](http://choosealicense.com/licenses/mit/)

Contents
--------

[](#contents)

- [Key features](#key-features)
- [Installation](#installation)
    - [Migration](#migration)
    - [Models](#models)
        - [Role](#role)
        - [Permission](#permission)
        - [User](#user)
- [Concept](#concept)
    - [For example](#for-example)
- [Usage](#usage)
    - [Permission checking](#permission-checking)
        - [Simple checking](#simple-checking)
        - [Middleware](#middleware)
        - [Blade](#blade)
    - [Role checking](#permission-checking)
        - [Simple checking](#simple-checking)
    - [Attaching, detaching](#attaching-detaching)
        - [Attach to a user](#attach-to-a-user)
        - [Detach from a user](#detacg-from-a-user)
        - [Attach to a role](#attach-to-a-role)
        - [Detach from a role](#detach-from-a-role)

Key features
------------

[](#key-features)

1. You have roles and permissions. Permissions can be attached to a role, and roles can be attached to a single user, but also you can **attach or detach permission/permissions from a specific user.**
2. Permissions and roles are stored in the **cache**, editing them automatically refreshes it. We use cache tags, so regular file or database cache drivers doesn't work, please use **memcached** instead.
3. **Inspired by [Zizaco/entrust](https://github.com/Zizaco/entrust)**
4. Please note, the package is under development, only tested with **Laravel 5.2**.

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

[](#installation)

Add the following line to your **composer.json** (Laravel 5.4 and below):

```
"xdroidteam/xtrust": "0.1.*"

```

Add the following line to your **composer.json** (Laravel 5.5):

```
"xdroidteam/xtrust": "0.2.*"

```

Then run `composer update`.

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

```
composer require xdroidteam/xtrust

```

Then in your `config/app.php` add to the `providers` array (not needed after Laravel 5.5):

```
XdroidTeam\XTrust\XTrustServiceProvider::class,
```

and to `aliases` array (not needed after Laravel 5.5):

```
'XTrust' => XdroidTeam\XTrust\XTrust::class,
```

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

```
'permission' => \XdroidTeam\XTrust\Middleware\XTrustPermissionMiddleware::class,
```

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

### Migration

[](#migration)

Deploy migration file:

```
php artisan vendor:publish --tag=xdroidteam-xtrust
```

You may now run it with the *artisan migrate* command:

```
php artisan migrate
```

### Models

[](#models)

#### Role

[](#role)

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

```
