budhaspec/rolepermission
Composer 安装命令:
composer require budhaspec/rolepermission
包简介
Allow admin to create module/sub module and assign a permissions to user. User can then access module as per the permission assigned to them.
README 文档
README
Please check the official laravel installation guide for server requirements before you start. Official Documentation
About RolePermission
A lightweight and customizable Role & Permission management system tailored for Laravel admin panels—built with no third-party dependencies.
You can define your own modules and sub-modules, create custom roles, and assign specific permissions to those roles.
Once permissions are set, simply assign the role to a user to control access.
Installation
Install the package via Composer:
composer require budhaspec/rolepermission
Run the database migrations (ensure your .env file is configured properly):
php artisan migrate
Publish the public assets:
php artisan vendor:publish --tag=public
Update user model as below.
use Budhaspec\Rolepermission\Models\Role;
Add 'role_id' in $fillable array.
Add below relationship.
public function role() {
return $this->belongsTo(Role::class, 'role_id');
}
Start the local development server:
php artisan serve
You can now access the server at http://127.0.0.1:8000/
Usage
Middleware & Route Protection
Configure middleware in bootstrap/app.php
use Budhaspec\Rolepermission\Http\middleware\CheckPermission;
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'role-permission' => CheckPermission::class,
]);
})
Wrap any routes you want protected by roles and permissions inside the role-permission middleware:
Route::middleware(['auth', 'role-permission'])->group(function () {
Route::get('/product/list', fn () => 'Outer Product List')->name('product.list');
Route::get('/product/add', fn () => 'Outer Product add')->name('product.add');
});
Only users with the appropriate role and permission will be able to access the routes inside this group.
Modules
Manage modules and sub-modules from:
This section allows you to define features (modules) and their actions (sub-modules) that need to be permission-controlled.
Roles
Manage roles and assign permissions via:
From here, you can:
- Create and edit roles
- Assign module and sub-module permissions to roles
- Assign roles to users
Permissions Mapping Convention
Important: THE NAMED ROUTE MUST MATCH THE MODULE.SUB-MODULE NAME; otherwise, IT WON'T WORK.
From the roles section you can manage roles, Assign permissions (module/sub module) to specific role by clicking on 'Assign Permission' button.
You can assign that Role to specific users for given a grant of that module/sub module.
Suppose product is module and list, add, edit and delete are sub modules assigned to manager role.
Manager role assigned to budha.test@gmail.com user then that user can access product and it's
sub module list, add, edit and delete routes.
Consider the below test cases for product module.
Correct Format:
Route::get('/product/list', fn () => 'Product List')->name('product.list');
Incorrect Formats:
Route::get('/product/list', fn () => 'Product List')->name('product.listing'); // Invalid
Route::get('/product/list', fn () => 'Product List')->name('products'); // Invalid
------------------------------------------------------------------------------------------------------------------------
| Module | Sub-Module | Valid Route Name | Invalid Examples |
| ------- | ---------- | ---------------- | ------------------------------------- |
| product | list | `product.list` | `product.listing`, `products.listing` |
| product | add | `product.add` | `product.create`, `product.insert` |
| product | edit | `product.edit` | `product.update` |
| product | delete | `product.delete` | `product.destroy`, `product.remove` |
Important: In short, named route must be module.sub module name like 'product.list' then it will work.
Example:
If the module is product and sub-module is edit, then the named route must be product.edit
Route::get('/product/{id}/edit', fn () => 'Edit Product')->name('product.edit'); // ✅ Valid
budhaspec/rolepermission 适用场景与选型建议
budhaspec/rolepermission 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 budhaspec/rolepermission 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 budhaspec/rolepermission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-07