權(quán)限包地址:https://github.com/Zizaco/entrust
OK灾而,首先安裝Zizaco/Entrust包
"zizaco/entrust": "5.2.x-dev"
providers array:
Zizaco\Entrust\EntrustServiceProvider::class,
aliases array:
'Entrust' => Zizaco\Entrust\EntrustFacade::class,
運(yùn)行下面命令發(fā)布配置文件
php artisan vendor:publish
打開config/auth.php胡控,配置
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => Namespace\Of\Your\User\Model\User::class,
'table' => 'users',
],
],
如果你想使用中間介
'role' => \Zizaco\Entrust\Middleware\EntrustRole::class,
'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class,
'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class,
在app/Http/Kernel.php中添加
OK,上面的基本安裝已經(jīng)差不多了旁趟,現(xiàn)在我們遷移數(shù)據(jù)庫
php artisan entrust:migration
php artisan migrate
roles — 角色表
permissions — 權(quán)限表
role_user — 角色和用戶之間的關(guān)系
permission_role— 角色和權(quán)限之間的關(guān)系
OK, 接下來創(chuàng)建相對(duì)應(yīng)的模型
1.創(chuàng)建Role模型
<?
php namespace App;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
2.創(chuàng)建Permission模型
<?php
namespace App;
use Zizaco\Entrust\EntrustPermission;
class Permission extends EntrustPermission
{
}
3.創(chuàng)建Admin模型
<?php
use Zizaco\Entrust\Traits\EntrustUserTrait;
class Admin extends Eloquent
{
use EntrustUserTrait; // T添加到你的模型
...
}