PHPackages                             lucas-quinn-guru/cerberus - 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. lucas-quinn-guru/cerberus

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

lucas-quinn-guru/cerberus
=========================

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

0.1.4(7y ago)034MITPHPPHP &gt;=7.1.0

Since Jul 13Pushed 7y agoCompare

[ Source](https://github.com/lucas-quinn-guru/cerberus)[ Packagist](https://packagist.org/packages/lucas-quinn-guru/cerberus)[ RSS](/packages/lucas-quinn-guru-cerberus/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Cerberus (Laravel 5.6 Package)
==============================

[](#cerberus-laravel-56-package)

[![License](https://camo.githubusercontent.com/32dadc8fc38f1721d83fb162d7726f1c4961c4e8bb5cb4e61eb24f0ee716e0cb/68747470733a2f2f706f7365722e707567782e6f72672f6c756361732d7175696e6e2d677572752f63657262657275732f6c6963656e73652e737667)](https://packagist.org/packages/lucas-quinn-guru/cerberus)[![Total Downloads](https://camo.githubusercontent.com/77ad90485a0a8463ecdbb917df7593b96ced72d72648807685a60a4dd1d27061/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c756361732d7175696e6e2d677572752f63657262657269732e737667)](https://packagist.org/packages/lucas-quinn-guru/cerberus)

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

This is a fork from zizaco/entrust.

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 5.6 Cerberus, just add the following to your composer.json. Then run `composer update`:

```
"LucasQuinnGuru/cerberus": "1.0.x-dev",
```

2. Open your `config/app.php` and add the following to the `providers` array:

```
LucasQuinnGuru\Cerberus\CerberusServiceProvider::class,
```

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

```
'Cerberus'   => LucasQuinnGuru\Cerberus\CerberusFacade::class,
```

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

```
php artisan vendor:publish
```

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) (requires Laravel 5.1 or later) you also need to add the following:

```
    'role' => \LucasQuinnGuru\Cerberus\Middleware\CerberusRole::class,
    'permission' => \LucasQuinnGuru\Cerberus\Middleware\CerberusPermission::class,
    'ability' => \LucasQuinnGuru\Cerberus\Middleware\CerberusAbility::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 Cerberus to refer to the correct user table and model.

To further customize table names and model namespaces, edit the `config/cerberus.php`.

### User relation to roles

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

Now generate the Cerberus migration:

```
php artisan cerberus:migration
```

It will generate the `_cerberus_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:

```
