i74ifa/role-craft
Composer 安装命令:
composer require i74ifa/role-craft
包简介
automating role creation and permission management with Spatie/Laravel-Permission.
README 文档
README
Installation
composer require i74ifa/role-craft
Version Compatibility
| Version | Laravel | Spatie Permission | PHP |
|---|---|---|---|
| v2.x | 12.0+ / 13.0+ | 7.0+ | 8.4+ |
| v1.x | 10.0+ / 11.0+ | 6.x | 8.2+ |
optional
publish config
php artisan vendor:publish --tag=role-craft-config
AI agent guide
This package ships an agent-neutral usage guide for AI coding assistants at:
vendor/i74ifa/role-craft/docs/AGENT_GUIDE.md
It covers every config key, command flag, per-model override, naming rule, and common recipe in one place. It is plain Markdown — readable by humans and by any agent (Cursor, Cline, Aider, GitHub Copilot, Codex, Claude Code, etc.).
To make your agent pick it up automatically, reference the path from whichever rules file your tool uses, for example:
AGENTS.md(Codex / generic) — link or include the file..cursor/rules/*.mdc(Cursor) —@vendor/i74ifa/role-craft/docs/AGENT_GUIDE.md..github/copilot-instructions.md(GitHub Copilot) — link to the file.CLAUDE.mdor.claude/skills/role-craft/SKILL.md(Claude Code) — link to or copy the file..clinerules,.windsurfrules,.continuerules— reference the file path.
Usage
Generate role and Permissions
php artisan role-craft:generate
this command will be generate all permissions and role-craft.default_role will be created
if you want to change default role name, you can change it in config/role-craft.php after publish config
Sync permissions
php artisan role-craft:sync manager --all
this will be sync all permissions to manager role if it exists
if not exists you want to use --create option
php artisan role-craft:sync manager --create
if you want to sync some role from models use --models option
php artisan role-craft:sync manager --models=User --models=Post # OR Custom Directory php artisan role-craft:sync manager --models=App\Models\Directory\User
Generate role if not exists
php artisan role-craft:sync manager --create
Including models (whitelist)
Some projects don't need permissions for every model in app/Models. To restrict scanning to a curated set, fill included_models in config/role-craft.php. When the list is non-empty, role-craft only processes models matching one of the patterns — everything else is treated as "excluded all":
// config/role-craft.php 'included_models' => [ App\Models\User::class, // exact class 'App\Models\Billing\*', // whole subtree '*\Public\*', // any "Public" folder anywhere ],
When included_models is empty (the default), every Eloquent model under models_path is included.
Excluding models (blacklist)
If you want to skip one or more models, add them to the excluded_models array. Excludes are applied after the include filter, so you can whitelist a subtree and then carve a few classes out of it:
// config/role-craft.php 'excluded_models' => [ App\Models\User::class, // exact class 'App\Models\Internal\*', // every model under app/Models/Internal '*\Pivot\*', // any "Pivot" folder anywhere ],
Notes:
- Both filters use
fnmatchon the fully-qualified class name (leading backslashes are normalized). - The filters are only applied during directory scans. Passing
--models=Fooexplicitly still includesFoo— user intent wins. - Order of operations:
included_modelsfirst (if non-empty), thenexcluded_models.
Per-model customization
Override the permission name or action list on a specific model by declaring public properties on it:
class Post extends Model { // Replaces the table-name segment in the permission name public $prefix_permissions = 'blog_posts'; // Replaces the default action list for this model public $prefix_model_permissions = ['create', 'view', 'publish', 'archive']; }
License
This package is released under the MIT license.
i74ifa/role-craft 适用场景与选型建议
i74ifa/role-craft 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「permission」 「role」 「spatie」 「laravel-permission」 「i74ifa」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 i74ifa/role-craft 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 i74ifa/role-craft 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 i74ifa/role-craft 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
The library provides a flexible way to add role-based access control management to CakePHP 3.x
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
This package provides a flexible way to add Role-based Permissions to Laravel
A Laravel Nova tool for `ACL` based on `laratrust` package.
Menu and role management helper.
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-28