curly-deni/laravel-permission-policy
最新稳定版本:v1.2.2
Composer 安装命令:
composer require curly-deni/laravel-permission-policy
包简介
A lightweight Laravel package for reusable, trait-based policy checks supporting CRUD, ownership, and private resource access.
关键字:
README 文档
README
A simple and flexible way to define and apply CRUD policies in Laravel using traits.
Designed to work seamlessly with laravel-permission-maker 🎯
✨ Features
- ✅ Out-of-the-box CRUD permission checks
- 🔒 Support for private resource visibility
- 👤 Ownership-based access control
- 🧩 Easy integration using traits
- ⚙️ Configurable behavior via simple settings
📦 Installation
Install the package via Composer:
composer require curly-deni/laravel-permission-policy
⚙️ Configuration
After publishing the config file with:
php artisan vendor:publish --tag="permission-policy-config"
You’ll get the following settings in config/permission-policy.php:
return [ 'register_gate' => true, // Automatically register default gate with policy bindings // Toggle specific permission checks: 'read_check' => false, // Use 'read' instead of 'view' 'view_check' => true, // Check for 'view' permission 'create_check' => true, // Check for 'create' permission 'update_check' => true, // Check for 'update' permission 'delete_check' => true, // Check for 'delete' permission ];
🛠️ Note: If you disable the automatic
gateregistration ('register_gate' => false), make sure your custom gate implementation supports passing policy arguments via query parameters. You can use the included helper functions to handle this:
encodeClassWithParams(string $class, array $params): string> Encodes a class name and arguments into a query-safe string.
decodeClassWithParams(string $encoded): array> Decodes the encoded string back into the original class name and parameters.
🚀 Usage
This package is intended to be used with laravel-permission-maker.
Choose the trait that suits your needs:
| Trait | Description |
|---|---|
HasResourcePolicy |
Basic CRUD permission checks |
HasPrivateResourcePolicy |
Adds private resource view checks |
HasOwnResourcePolicy |
Enables edit/delete for own resources |
HasOwnAndPrivateResourcePolicy |
Combines ownership and private access |
🤝 Contributing
See CONTRIBUTING.md for contribution guidelines.
🙌 Credits
📄 License
This package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-03