Zizaco /entrust

Role-based Permissions for Laravel 5

★ 5,992⑂ 1,267👁 251⑃ 306● 689▤ 12
PHPMITCreated 2013-02-07
Download: 5.2 Release5.2-1.7.0 ↓1.7.02016-03-09
+0
Daily
5,992
stars
1,267
forks
251
watchers
306
prs
689
issues
12
releases

README

ENTRUST (Laravel 9|10 Package)

Forked from zizaco/entrust

Entrust is a succinct and flexible way to add Role-based Permissions to Laravel 9|10.

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

 Contents

- ENTRUST (Laravel 9|10 Package)
  - Contents
  - Installation
  - Configuration
    - User relation to roles
    - Models
      - Role
      - Permission
      - User
      - Soft Deleting
  - Usage
    - Concepts
      - Checking for Roles \& Permissions
      - User ability
    - Blade templates
    - Middleware
    - Short syntax route filter
    - Route filter
  - Troubleshooting
  - License
  - Contribution guidelines

 Installation

1) In order to install Laravel 5 Entrust, just add the following to your composer.json. Then run composer update:

json
"zizaco/entrust": "5.2.x-dev"


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

php
Zizaco\Entrust\EntrustServiceProvider::class,


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

php
'Entrust'   = Zizaco\Entrust\EntrustFacade::class,


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

shell
php artisan vendor:publish


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

php
'providers' = [
    'users' = [
        'driver' = 'eloquent',
        'model' = Namespace\Of\Your\User\Model\User::class,
        'table' = 'users',
    ],
],


6)  If you want to use Middleware (requires Laravel 5.1 or later) you also need to add the following:

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


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

 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

Now generate the Entrust migration:

bash
php artisan entrust:migration


It will generate the _entrust_setup_tables.php migration.
You may now run it with the artisan migrate command:

bash
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 relations between roles and users
- permission_role — stores many-to-many relations between roles and permissions

 Models

 Role

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

php
delete(); // This will work no matter what

// Force Delete
$role-users()-sync([]); // Delete relationship data
$role-perms()-sync([]); // Delete relationship data

$role-forceDelete(); // Now force delete will work regardless of whether the pivot table has cascading delete


 Usage

 Concepts
Let's start by creating the following Roles and Permissions:

Top issues

Latest release

5.2 Release 1.7.0 2016-03-09

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON