alifcoder/permissions
Composer 安装命令:
composer require alifcoder/permissions
包简介
A simple role and permission management package for Laravel.
README 文档
README
A simple, flexible role and permission management system for Laravel applications — designed to support
Gate::before, SUPER ADMIN logic, modular apps (nwidart/laravel-modules), and dynamic user model resolution.
✨ Features
- Role and permission management with pivot tables
SUPER ADMINbypass support usingGate::before()HasRolestrait for easy user integration- Dynamically configurable user model
- Language file localization (EN, customizable)
- Clean service provider with publishable config and migrations
- Works with modular Laravel apps (like
nwidart/laravel-modules)
📦 Requirements
- PHP
>=8.2 - Laravel
^11.0 || ^12.0 || ^13.0
🚀 Installation
composer require alifcoder/permissions
Then publish the config, translations, and migrations:
php artisan vendor:publish --tag=permissions php artisan migrate
This will publish:
lang/vendor/permissionsconfig/permission.phpdatabase/migrations/xxxx_xx_xx_xxxxxx_create_permissions_table.php
⚙️ Configuration
Inside config/permissions.php:
return [ 'models' => [ 'role' => \Alif\Permissions\Models\Role::class, 'permission' => \Alif\Permissions\Models\Permission::class, ], 'cacheable' => true, 'is_model_uuid' => true, ];
You can override the default user model or super-admin slug here.
🧬 Traits
In your User model, add the trait:
use Alif\Permissions\Traits\HasRoles; class User extends Authenticatable { use HasRoles; }
🔐 Super Admin Access
Add this in your app (e.g., AuthServiceProvider) — or it's auto-registered by the package:
Gate::before(function ($user, $ability) { return $user->isSuperAdmin() ? true : null; });
This lets super-admin users bypass all policy/gate checks.
🧠 Usage
Assign Roles & Permissions
$admin = Role::create(['name' => 'Admin', 's_code' => 'admin']); $edit = Permission::create(['name' => 'products.update']); $admin->permissions()->attach($edit->id); $user->syncRoles($admin->id);
Check Permissions
$user->hasAllRoles('admin'); // true $user->hasAnyRoles('admin'); // true $user->hasPermission('products.update'); // true $user->isSuperAdmin(); // true or false
🌐 Localization
The package includes English (en) translations. To override or translate:
Then add resources/lang/vendor/permissions/{locale}/permissions.php.
🧑💻 Usage macro
Also you can use Route macro to check permissions and roles:
Route::put('/products/{product}', function () { // Your logic here })->permission('products.update'); Route::put('/admin', function () { // Your logic here })->role('admin');
🧩 Folder Structure
src/
├── Models/
│ ├── Role.php
│ └── Permission.php
├── Traits/
│ └── HasRoles.php
├── Middleware/
├── Console/
├── PermissionServiceProvider.php
config/
└── permissions.php
resources/
└── lang/en/permissions.php
database/
└── migrations/
🧹 Clear permission caches
Run this command to clear the permission cache:
php artisan permission:cache:clear
🧹 Uninstall (Clean Up)
Run this command before removing the package:
php artisan permission:uninstall
📜 License
MIT © Shukhratjon Yuldashev
🙌 Contributing
Pull requests and suggestions are welcome!
alifcoder/permissions 适用场景与选型建议
alifcoder/permissions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alifcoder/permissions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alifcoder/permissions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 104
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-17