livelyworks / laravel-yes-authority
YesAuthority - Laravel 路由权限库
2.9.16
2023-02-28 18:22 UTC
Requires
- php: >=5.4.0
- laravel/framework: >=5.1
- livelyworks/laraware: >=1.2.6
- dev-master / 2.x-dev
- 2.9.16
- 2.9.15
- 2.9.14
- 2.9.12
- 2.9.11
- 2.9.10
- 2.9.9
- 2.9.8
- 2.9.7
- 2.9.6
- 2.9.5
- 2.9.3
- v2.9.1
- v2.9.0
- v2.8.0
- v2.7.8
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.0
- v2.3.2
- v2.3.1
- v2.3.0
- 2.1.8
- 2.1.7
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- v2.1.0
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.0
- 1.20.21
- dev-2.x-dev
- dev-1.x-dev
This package is auto-updated.
Last update: 2024-08-28 21:41:50 UTC
README
YesAuthority 是一个灵活的 Laravel 授权系统,它通过检查 route
权限来访问网站的特定部分或应用程序。可以通过 User-based
、Role-based
、Conditionally
添加权限。它使用 authority.checkpost
中间件来过滤当前访问路由的权限,在这个中间件中会检查用户登录的每一个权限。
安装
在您的 composer.json
中要求此包,或者通过运行以下命令进行安装:
composer require livelyworks/laravel-yes-authority
现在,将此行插入到您的 config/app.php
文件中的 provider
数组下。
LivelyWorks\YesAuthority\YesAuthorityServiceProvider::class
现在,在 config/yes-authority.php
和 app/Http/Middleware/YesAuthorityCheckpostMiddleware.php
文件发布后运行此命令。
php artisan vendor:publish --tag="yesauthority"
现在,将此行插入到您的 app/Http/Kernel.php
文件中的 $routeMiddleware
数组下。
'authority.checkpost' => \App\Http\Middleware\YesAuthorityCheckpostMiddleware::class
使用 authority.checkpost
中间件来处理基于权限的路由。
Route::group(['middleware' => 'authority.checkpost'], function () { // Place all those routes here which needs authentication and authorization. });
现在,基本设置就绪了。您需要使用 config/yes-authority
配置权限规则。
配置
以下列出了权限结构,但强烈建议您阅读更多关于 文档 的内容。
[ 'allow' => ['*'], // Allowed permission to user. Priority is less than deny. 'deny' => ['temp1'], // Deny permission to user. Priority is higher than allow. ] canAccess('temp1'); // false
用法 - 助手
canAccess('temp1'); // true or false
canPublicAccess(); // true or false
用法 - 门面
YesAuthority::check($accessId = null, $requestForUserId = null)
检查$accessId
的访问权限,默认情况下检查当前路由,并以布尔值返回响应。它还可以通过传递用户 ID($requestForUserId)
参数来检查特定用户的访问权限。
YesAuthority::check('temp1'); // true or false
YesAuthority::isPublicAccess($accessId = null); -
检查Authentication not required
$accessId
的访问权限,默认情况下检查当前路由,并以布尔值返回响应。
YesAuthority::isPublicAccess('temp1'); // true or false
用法 - 指令
@canAccess()
// your logic here.
@endAccess;
@canPublicAccess()
// your logic here.
@endAccess;