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

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

hwacom/entrust
==============

This package provides a flexible way to add role-based permissions to Laravel and extends from Zizaco/entrust and Trebol/entrust

v1.1.1(7mo ago)0347MITPHPPHP ^8.3

Since Aug 21Pushed 7mo agoCompare

[ Source](https://github.com/HwacomService/Entrust)[ Packagist](https://packagist.org/packages/hwacom/entrust)[ RSS](/packages/hwacom-entrust/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

SSO Client Package via Hwacom SSO
=================================

[](#sso-client-package-via-hwacom-sso)

[![Build Status](https://github.com/mozielin/Client-SSO/workflows/PHP Composer/badge.svg)](https://github.com/mozielin/Client-SSO/actions)[![Total Downloads](https://camo.githubusercontent.com/2db62124c9cd0207edeb7a389cb6c5adfe1e16338ba7221546299aac04ff1733/687474703a2f2f706f7365722e707567782e6f72672f687761636f6d2f636c69656e742d73736f2f646f776e6c6f616473)](https://packagist.org/packages/hwacom/client-sso)[![Latest Stable Version](https://camo.githubusercontent.com/ece3f14933e8a5667f2015e53b5841d38a9ee300762dcce0995aa441db2e0225/687474703a2f2f706f7365722e707567782e6f72672f687761636f6d2f636c69656e742d73736f2f76)](https://packagist.org/packages/hwacom/client-sso)

前言
--

[](#前言)

因為Zizaco/entrust 套件已經停止維護了， 但又好用到靠杯，所以暫時無法替換其他方案，只好接手繼續維護

Contents
--------

[](#contents)

- [安裝說明](#%E5%AE%89%E8%A3%9D%E8%AA%AA%E6%98%8E)
- [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)

安裝說明
----

[](#安裝說明)

```
composer require hwacom/entrust
```

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

```
Hwacom\Entrust\EntrustServiceProvider::class,
```

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

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

4. Run the command below to publish the package config file `config/entrust.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' => \Hwacom\Entrust\Middleware\EntrustRole::class,
    'permission' => \Hwacom\Entrust\Middleware\EntrustPermission::class,
    'ability' => \Hwacom\Entrust\Middleware\EntrustAbility::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 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:

```
