PHPackages                             hoanghiep/role - 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. hoanghiep/role

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

hoanghiep/role
==============

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

171PHP

Since Aug 13Pushed 9y ago2 watchersCompare

[ Source](https://github.com/thandonguocmo2020/Roles)[ Packagist](https://packagist.org/packages/hoanghiep/role)[ RSS](/packages/hoanghiep-role/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

ENTRUST (Laravel 5 Package)
===========================

[](#entrust-laravel-5-package)

[![Build Status](https://camo.githubusercontent.com/f0dd3d7b1fb8d7d7fe73a6fc644e1fd7a5c3d457734afbdce0e0ebccda234434/68747470733a2f2f7472617669732d63692e6f72672f5a697a61636f2f656e74727573742e737667)](https://travis-ci.org/Zizaco/entrust)[![Version](https://camo.githubusercontent.com/bba6a1ab9744aab3aaffd52c220871a8a51e8187f67d650f3dec9d834aac868f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f5a697a61636f2f656e74727573742e737667)](https://packagist.org/packages/zizaco/entrust)[![License](https://camo.githubusercontent.com/7254c1d715cc83039b0c4b02b58db99a82939ffdbc87652edac27fa984ceb4fa/68747470733a2f2f706f7365722e707567782e6f72672f7a697a61636f2f656e74727573742f6c6963656e73652e737667)](https://packagist.org/packages/zizaco/entrust)[![Total Downloads](https://camo.githubusercontent.com/9c2d0cdabee70745d07651a3c50ace28064e157c35055b6e6ad01bc41b16803d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a697a61636f2f656e74727573742e737667)](https://packagist.org/packages/zizaco/entrust)

[![SensioLabsInsight](https://camo.githubusercontent.com/0b1aa6bf92e58c3ebf1d5d2737f62dbbdc9b0f1f39190beb44d508e54933a386/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63633461663936362d383039622d346662632d623862322d6262323835306536373131652f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/cc4af966-809b-4fbc-b8b2-bb2850e6711e)

Entrust là một cách gọn gàng và linh hoạt để thêm vai trò người dùng Role-based và quyền hạn trong **Laravel 5**.

If you are looking for the Laravel 4 version, take a look [Branch 1.0](https://github.com/Zizaco/entrust/tree/1.0). It contains the latest entrust version for Laravel 4.

Contents
--------

[](#contents)

- [Cài đặt](#installation)
- [Fix Errors](#fixError)
- [Cấu hình](#configuration)
    - [Sử dụng mối quan hệ từ roles](#user-relation-to-roles)
    - [Models](#models)
        - [Role](#role)
        - [Permission](#permission)
        - [Người sử dụng User](#user)
        - [Xóa Deleting](#soft-deleting)
        - \[Cập nhập \]
- [Sử dụng](#usage)
    - [Các khái niệm - Gán vai trò cho user ](#concepts)
        - [Kiểm tra Vai trò &amp; Quyền - Checking for Roles &amp; Permissions](#checking-for-roles--permissions)
        - [Tư cách người dùng](#user-ability)
    - [Blade templates](#blade-templates)
    - [Middleware](#middleware)
    - [Cú pháp ngắn gọn cho bộ lọc route ](#short-syntax-route-filter)
    - [Route filter](#route-filter)
- [Xử lý sự cố](#troubleshooting)
- [giấy phép](#license)
- [hướng dẫn đóng góp](#contribution-guidelines)
- [Thông tin thêm](#additional-information)

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

[](#installation)

Để cài đặt Laravel 5 Entrust, chỉ cần thêm

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

```

từ composer.json của bạn. Chạy lệnh `composer install` hoặc `composer update`.

Hoặc bạn có thể chạy lệnh yêu cầu gói bằng `composer require` từ terminal của bạn:

```
composer require zizaco/entrust:5.2.x-dev

```

Trong file `config/app.php` thêm mới

```
    Hoanghiep\Role\EntrustServiceProvider::class,
```

hãy thêm nó trong `providers` mảng và

```
    'Entrust'   => Hoanghiep\Role\EntrustFacade::class,
```

trong `aliases` mảng.

Bạn có thể sử dụng Middleware [Middleware](#middleware) (yêu cầu từ Laravel 5.1 trở về sau) bạn cũng cần phải thêm

```
    'role' => \Hoanghiep\Role\Middleware\EntrustRole::class,
    'permission' => \Hoanghiep\Role\Middleware\EntrustPermission::class,
    'ability' => \Hoanghiep\Role\Middleware\EntrustAbility::class,
```

trong `routeMiddleware` mảng tại đường dẫn `app/Http/Kernel.php`.

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

[](#configuration)

thiết lập các giá trị tài sản property values trong `config/auth.php`. Những giá trị này sẽ được sử dụng bởi ủy thác để tham khảo bảng use và model.

config/auth.php thay đổi providers key thành

```
**
'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
            'table' => 'users',
        ],
],
**

```

Bạn cũng có thể xuất bản các cấu hình cho các gói này để tùy chỉnh thêm các tên bảng và không gian tên mô hình. Sử dụng câu lệnh `php artisan vendor:publish` và 1 `entrust.php` file mở rộng được tại ra tại app/config directory.

### User relation to roles

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

Bây giờ tạo ra một migration tạo cấu trúc bảng Entrust migration bằng lệnh:

```
php artisan entrust:migration
```

Nó sẽ tạo ra `_entrust_setup_tables.php` file migration. Bây giờ bạn có thể chạy nó với lệnh :

```
php artisan migrate
```

Sau đó các bảng mới sẽ có mặt :

- `roles` — BẢNG CHỨA VAI TRÒ CỦA NGƯỜI DÙNG TRÊN HỆ THỐNG. VÍ DỤ USER HIỆN TẠI LÀ :. "admin","Chủ dự án", "Nhân viên công ty"..v.v
- `permissions` — CHỨA THÔNG TIN VỀ QUYỀN HẠN VỚI CÁC LAYOUT TRONG HỆ THỐNG VÍ DỤ NGƯỜI DÙNG LÀ CHỦ DỰ ÁN CÓ QUYỀN.Thêm - Sửa Xóa. ví dụ "create-post","edit-user"..v.v. phù hợp từng vai trò sẽ có quyền phù hợp.
- `role_user` — Chứa [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) quan hệ giữa người sử dụng và vai trò của họ trên hệ thống. roles và users
- `permission_role` — Chứa [many-to-many](http://laravel.com/docs/4.2/eloquent#many-to-many) quan hệ giữa vai trò và quyền hạn phù hợp nó.

### Models

[](#models)

#### Role

[](#role)

Tạo ra một Model Role `app/models/Role.php` để áp dụng trong ví dụ :

```
