定制 rodrigopedra/laravel-simple-acl 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rodrigopedra/laravel-simple-acl

最新稳定版本:v1.2.0

Composer 安装命令:

composer require rodrigopedra/laravel-simple-acl

包简介

Laravel Simple ACL

关键字:

README 文档

README

Requirements

  • PHP 8.1+
  • Laravel 9+

Installation

{
    "require": {
        "rodrigopedra/laravel-simple-acl": "^1.0"
    }
}
  • Export configuration and set the project's User model class name
    • default is: App\Models\User
  • Add \RodrigoPedra\LaravelSimpleACL\Concerns\HasACL trait to the project's User model
  • Run migrations
  • Optionally load the included Middleware
    • This will load and cache a logged in user's roles and permissions and define a gate to each permission

Usage

Create roles and permissions through the included RodrigoPedra\LaravelSimpleACL\Models\Role and RodrigoPedra\LaravelSimpleACL\Models\Permission Eloquent models.

Permissions are meant to be grouped into a role, you can create a database seeder, or migration for your initial setup, for example:

$addUsers = Permission::create([
    'label' => 'add-users',
    'description' => 'User is allowed to create new users',
    'sort_index' => 1,
]);

$removeUsers = Permission::create([
    'label' => 'remove-users',
    'description' => 'User is allowed to remove users',
    'sort_index' => 2,
]);

Role::create([
    'label' => 'admin',
    'sort_index' => 1,
])->attachPermission($addUsers)->attachPermission($removeUsers);

Role::create([
    'label' => 'leader',
    'sort_index' => 2,
])->attachPermission($addUsers);

You can then add or remove roles to individual users using the included trait's helper methods:

$user->attachRole(Role::hasLabel('admin')->first());
$user->detachRole(Role::hasLabel('leader')->first());

If you add the \RodrigoPedra\LaravelSimpleACL\Http\Middleware\LoadSimpleACL middleware to your middleware stack, you can use Laravel's gate to check for permissions:

if ($user->can('add-users')) {
    // do something
}

Even on blade views

@can('add-users')
    {{-- do something --}}
@endcan

统计信息

  • 总下载量: 656
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固