yuriy-martini/laravel-authorization
最新稳定版本:v0.1.1
Composer 安装命令:
composer require yuriy-martini/laravel-authorization
包简介
README 文档
README
Laravel Authorization
https://laravel.com/docs/master/authorization#introduction
Installation
composer require yuriy-martini/laravel-authorization
Usage
https://laravel.com/docs/master/authorization#authorizing-actions-using-policies
- Authorizable (User)
- Config
- Policies
U/ Authorizable
U/ A/ Example
-+ app/Models/User.php:
<?php namespace App\Models; class User implements \YuriyMartini\Laravel\Authorization\Contracts\Authorizable { use \YuriyMartini\Laravel\Authorization\Concerns\Authorizable; }
U/ Config
U/ C/ Defaults
php artisan vendor:publish --tag=authorization-defaults-config
U/ C/ Models
php artisan vendor:publish --tag=authorization-models-config
U/ C/ M/ Example
+ config/authorization/models.php:
<?php return [ \App\Models\User::class => [ \App\Models\User::class => [ YuriyMartini\Laravel\Authorization\Enums\Permission::view, ], ], ];
U/ Models
U/ M/ Example
+ app/Models/User/Authorizations.php:
<?php namespace App\Models\User; trait Authorizations { public function isViewable(Authorizable $user): bool { return true; // here: ur BL } public function isUpdatable(Authorizable $user): bool { return true; // here: ur BL } public function isDeletable(Authorizable $user): bool { return true; // here: ur BL } public function isRestorable(Authorizable $user): bool { return true; // here: ur BL } public function isForceDeletable(Authorizable $user): bool { return true; // here: ur BL } }
-+ app/Models/User.php:
<?php namespace App\Models; class User implements \YuriyMartini\Laravel\Authorization\Contracts\Model { use \App\Models\User\Authorizations; }
U/ Policies
https://laravel.com/docs/master/authorization#generating-policies
U/ P/ Example
-+ app/Policies/UserPolicy.php:
<?php namespace App\Policies; class UserPolicy extends \YuriyMartini\Laravel\Authorization\Policy { protected static function getModel(): string { return \App\Models\User::class; } }
Changelog
Please see Changelog File for more information on what has changed recently.
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-10-16