laravolt / acl
基本的 Laravel ACL
Requires
- php: >=7.2
- illuminate/database: ~5.6|^6.0
- illuminate/support: ~5.6|^6.0
- spatie/once: ^2.1
- 4.2.4
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- dev-master / 4.0.x-dev
- 4.0.1
- 4.0.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.x-dev
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.x-dev
- 0.2
- 0.1
- dev-dependabot/composer/illuminate/database-6.19.1
- dev-feature/acl-repo2
This package is auto-updated.
Last update: 2024-05-15 20:24:27 UTC
README
安装
Composer
composer require laravolt/acl
服务提供者
如果您使用 Laravel 5.5 或更高版本,请跳过此步骤。
Laravolt\Acl\ServiceProvider::class,
迁移
发布迁移文件 (可选)
php artisan vendor:publish --provider="Laravolt\Acl\ServiceProvider" --tag=migrations
运行迁移
php artisan migrate
发布配置 (可选)
php artisan vendor:publish --provider="Laravolt\Acl\ServiceProvider" --tag=config
用法
将 Laravolt\Acl\Traits\HasRoleAndPermission
特性添加到 User
模型
<?php namespace App; use Laravolt\Acl\Traits\HasRoleAndPermission; class User { use HasRoleAndPermission; }
之后,User
将具有以下方法
$user->roles()
定义 User
有多个 Laravolt\Acl\Models\Role
关系的关联。
$user->hasRole($role, $checkAll = false)
检查特定 User
是否有一个或多个角色。返回布尔值 true 或 false。
$user->assignRole($role)
将一个或多个角色分配给特定 User
。可能的 $role
值有:id
、id
的数组、角色名称、Role
对象,或 Role
对象的数组。
$user->revokeRole($role)
从特定 User
中撤销/删除一个或多个角色。可能的 $role
值有:id
、id
的数组、角色名称、Role
对象,或 Role
对象的数组。
$user->hasPermission($permission, $checkAll = false)
检查特定 User
是否有一个或多个权限。返回布尔值 true 或 false。
命令
php artisan laravolt:acl:sync-permission
绕过授权
您可以使用 Laravel 内置方法绕过授权检查
// Place it somewhere before application running, e.g. in `AppServiceProvider`. Gate::before(function($user){ // check if $user superadmin // and then return true to skip all authorization checking });