承接 hasanhawary/permission-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

hasanhawary/permission-manager

最新稳定版本:v1.0.1

Composer 安装命令:

composer require hasanhawary/permission-manager

包简介

A simple permission and role management service extracted from the app for reuse.

README 文档

README

Latest Stable Version Total Downloads PHP Version License

A simple but powerful role & permission manager for Laravel, built on top of spatie/laravel-permission.

✨ Features

  • One-line setup: Access::handle() builds roles & permissions automatically.
  • Ships with default roles (root, admin).
  • Auto-discovers your models and generates permissions (create-user, update-project, etc.).
  • Config-driven roles: inheritance (like), add/remove (added, exception), and custom permission sets.
  • Additional operations for global actions not tied to models.
  • Translation-ready: multilingual display_name for roles & permissions (e.g., English & Arabic).
  • Works with Laravel Modules as well as app/Models.

📦 Installation

composer require hasanhawary/permission-manager

The service provider is auto-discovered.

Optionally publish the config:

php artisan vendor:publish --tag=permission-manager-config

This creates config/roles.php.

⚡ Quick Start: Build Everything

Use the facade for the simplest bootstrap:

use HasanHawary\PermissionManager\Facades\Access;

// Full rebuild (truncates & regenerates roles/permissions)
Access::handle();

// Just regenerate without resetting
Access::handle(skipReset: true);

Or run the artisan command:

php artisan permissions:reset

Both do the same thing under the hood.

🗂 Model-level Permissions

Define permissions directly in your models:

class Report
{
    public bool $inPermission = true;

    // Override CRUD (defaults: create/read/update/delete)
    public array $basicOperations = ['read', 'update'];

    // Add custom operations
    public array $specialOperations = ['export'];
}

Generated permissions:

read-report
update-report
export-report

⚙️ Config Example (config/roles.php)

'roles' => [
    'manager' => [
        'like' => 'admin',      // inherit from admin
        'type' => 'exception',  // remove selected permissions
        'permissions' => [
            'project' => ['delete'], // manager cannot delete projects
        ],
    ],
    'auditor' => [
        'permissions' => [
            'report' => ['read', 'export'],
        ],
    ],
],

'additional_operations' => [
    [
        'name' => 'ReportBuilder',
        'operations' => ['main'], // generates "main-reportbuilder"
        'basic' => true           // also add CRUD ops
    ]
],

'default' => [
    'permissions' => ['dashboard-access'],
],

🌍 Translations

This makes it easy to show localized names in dashboards, logs, or admin panels.

Example language file lang/ar/roles.php:

<?php

return [
    'root'  => 'المدير الافتراضى',
    'admin' => 'المدير',
];

Usage:

use HasanHawary\PermissionManager\Access;

Access::handle('admin'); // المدير

✅ Why this package?

  • Access::handle() = full automation
  • Default roles always exist (root, admin)
  • Translate-ready permissions (display_name in multiple languages)
  • Config-based role inheritance (like, exception, added)
  • Extra operations beyond models (ReportBuilder, etc.)
  • Supports Laravel Modules out of the box

✅ Version Support

  • PHP: 8.0 – 8.5
  • Laravel: 8 – 12

📜 License

MIT © Hasan Hawary

统计信息

  • 总下载量: 83
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-21