curly-deni/laravel-permission-policy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

Latest Version on Packagist Code Style Total Downloads

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 gate registration ('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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03