ohhink / rrm
Laravel RBAC 基于 Laravel-Permission 的后端 UI
Requires
- php: ^7.2
- earnp/laravel-google-authenticator: dev-master
- predis/predis: ^1.1
- simplesoftwareio/simple-qrcode: ^2.0.0
- spatie/laravel-permission: ^3.0
This package is auto-updated.
Last update: 2024-09-08 12:43:59 UTC
README
此包用于基于角色的规则控制器
此包基于 Laravel Permission,可以在几分钟内构建具有 UI 的规则控制器面板。
服务器要求:
- Php >= 7.2
- Laravel 版本 >= 6.1 && < 7.0 (不支持 Laravel 版本 >= 7.0,将很快更新)
包含内容
常量
本文中的“规则”可以视为 Laravel 中的“路由”
我为什么要这样做
言辞是廉价的,给我看代码!
Laravel Permission 是一个非常好的没有 UI 的包。所以,这个包在 Laravel Permission 包上添加了 UI,并做了一些事情来快速构建面板。
包含内容:
- 规则 控制器基于 角色,您可以为用户添加多个角色。
- 为角色添加多个规则。
- 菜单可以不同,因为它取决于用户拥有的规则。
- 在
routes/web.php
中编写您的新规则,然后可以通过一个按钮将其添加到程序中。 - 记录操作,您可以选择使用作业来同步/异步执行。
- 后端 UI 面板
- Google Authenticator
安装
建议使用新的 Laravel 项目,请务必在
php.ini
中打开exec
,shell_exec
,proc*
函数。
更新本地配置文件 .env
# change database and key # change cache CACHE_DRIVER=redis REDIS_CLIENT=predis # suggest QUEUE_CONNECTION=redis # google authenticator GOOGLE_AUTHENTICATOR=false
在您的新 Laravel 项目的根目录中运行 composer 命令。
$ composer require ohhink/rrm
发布文件,包括 admin.php
,filesystems.php
,permission.php
和前端资源文件以及数据库种子文件。
$ php artisan vendor:publish
# if you want to reload latest package seeder, run this command in force. It will remove the origin seeder , so please be careful
$ php artisan vendor:publish --tag=seeds --force
构建数据库并运行种子
# run autoload first to update the userseeder
$ composer dump-autoload
$ php artisan migrate:refresh --seed
$ php artisan db:seed --class=RrmDatabaseSeeder
给予文件夹权限和软链接
$ chmod -R 777 storage $ php artisan storage:link
如果您想使用 Google Authenticator,您必须自己添加此提供者和别名。
// config/app.php 'providers' => [ //........ Earnp\GoogleAuthenticator\GoogleAuthenticatorServiceprovider::class, SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class, ], 'aliases' => [ //.......... 'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class ],
就是这样!
如何使用
-
后端路由的默认值为
/admin
,这可以通过config/admin.php
进行更改。种子已经创建了一个超级管理员用户,其账户如下。account : admin@gmail.com password : admin&%@cv..
-
RBAC 讨论的是,将一个或多个规则分配给一个角色,并将一个或多个角色分配给一个用户。我们可以通过角色来控制规则,这是我们通常做的事情,而不是详细规则。因此,您需要执行一些与业务逻辑相关的步骤。
- 完成您的代码,并在 route/web.php 中添加您的路由,就像您通常做的那样。
- 点击 Route Reload。例如,我们得到了新的路由 admin.test。
- 在路径 resources/vendor/rrm/zh-cn/permission.php 中创建或更新您的翻译文件。
- 将此新路由分配给角色,如 admin。
- 如果此新路由是菜单功能,您应该创建一个新菜单并重新构建菜单,否则新菜单将不会显示。
-
如果您想重写路由,您应该在 route/web.php 中添加以下内容:
# this is rewrite the route to your app/Http/Controllers/IndexController.php index() Route::prefix(config('admin.prefix'))->middleware([ 'auth', 'admin' ])->name('admin.')->group(function () { Route::get('/', 'IndexController@index')->name('index'); });
在您的 app/Http/Controllers/IndexController.php 文件中,您应该添加以下内容:
public function index() { // put your code here !!! // recover the view in /resources/views/vendor/rrm/admin/index.blade.php // OR you can just run command below, it will create blade files automatically // php artisan vendor:publish --tag=views --force return view('rrm::admin.index'); }
-
要在右侧栏中查看在线用户,您需要在
app/Console.Kernel.php
文件中添加命令,如下所示:protected function schedule(Schedule $schedule) { // $schedule->command('inspire') // ->hourly(); $schedule->command('admin-tool:cache-online-users')->everyMinute(); }
请记住在您的服务器中添加命令
* * * * * php /home/vagrant/blade_package/artisan schedule:run >> /dev/null 2>&1
-
由于它会记录用户在面板上所执行的每一步,如果您想异步处理,可以将
.env
文件中的键值QUEUE_CONNECTION=sync
更改为QUEUE_CONNECTION=redis
。这将使记录器使用作业异步记录操作,这将更快。当然,您必须首先添加Redis或PRedis包。 -
如果您想更改
500
页面,您可以创建一个resource/views/vendor/rrm/500.blade.php
文件来重写它。 -
监听队列命令
php artisan queue:work --queue=logs --sleep=3 --tries=3 # prefer to use supervisor # supervisor config file -- laravel-worker.conf [program:logs] process_name=%(program_name)s_%(process_num)02d command=php path_to/artisan queue:work --queue=logs --sleep=3 --tries=3 autostart=true autorestart=true user=root numprocs=2 redirect_stderr=true stdout_logfile=path_to/supervisor/logs.log save and run ** supervisorctl reload ** to reload it
-
该包的布局,您可以通过以下代码使用它。
@extends('rrm::admin.layout') @section('content') <section id="main-content"> <section class="wrapper"> @if (Session::has('success')) @include('rrm::admin.layout.success',['msg'=>Session::get('success')]) @endif @if (Session::has('error')) @include('rrm::admin.layout.error',['msg'=>Session::get('error')]) @endif <div class="row"> <div class="col-lg-12"> </div> </div> </section> </section> @endsection @section('js') @endsection @section('css') @endsection
-
使用谷歌身份验证器
# First , add config to the file .env GOOGLE_AUTHENTICATOR=true # After that, no matter which page the user going to visit , he will redirect to GOOGLE AUTHENTICATOR PAGE. # Follow the step and it will redirect to the normal page after register. # If you what to vertify in your code , you can learn from the fake code. public function index() { // $google code which is registered before // $vertify code to be verified if (\OhhInk\Rrm\Model\Google::CheckCode($google, $vertify)) { // pass } else { // fail } }
相关努力
- Laravel Permission - 将用户与权限和角色关联
维护者
贡献
随时加入!可以打开一个问题或提交PR。
标准README遵循贡献者公约行为准则。
许可
MIT © OhhInk