zohaib482/laravel-simple-rbac
Composer 安装命令:
composer require zohaib482/laravel-simple-rbac
包简介
Simple and lightweight Role-Based Access Control (RBAC) package for Laravel 11+ and 12 with authentication and email verification support
README 文档
README
A simple, lightweight Role-Based Access Control (RBAC) package for Laravel with built-in authentication and email verification support.
Features
- Role & permission management (many-to-many)
- Built-in authentication + email verification flow
- Bootstrap 5 styled auth views (login, register, verify-email, dashboard)
- Middleware:
role:admin,permission:manage-users, etc. - Blade directives:
@role,@permission,@anyrole - Easy integration via trait on User model
- Configurable (user model, default role, redirect paths)
Requirements
- PHP ^8.2
- Laravel ^12.0
Installation
-
Install the package via Composer:
composer require zohaib482/laravel-simple-rbac
-
Publish configuration, views and migrations,Seeder:
php artisan vendor:publish --tag=simple-rbac-config php artisan vendor:publish --tag=simple-rbac-views php artisan vendor:publish --tag=simple-rbac-migrations
Seeding Roles and Permissions
After publishing and running migrations, you need to seed the default roles and permissions:
Publish the seeder (if not already published):
php artisan vendor:publish --tag=simple-rbac-seeders
Run the seeder:
php artisan db:seed --class=RbacSeeder
Or add it to your DatabaseSeeder.php:
public function run(): void { $this->call([ RbacSeeder::class, // Your other seeders... ]); } ``` 3. Run migrations and seed default roles/permissions: ```bash php artisan migrate 4. Add the HasRoles trait to your User model (app/Models/User.php): ```php use Illuminate\Contracts\Auth\MustVerifyEmail; use Zohaib482\SimpleRbac\Traits\HasRoles; class User extends Authenticatable implements MustVerifyEmail { use HasRoles; // ... other traits and properties }
Quick Usage Examples
Assign roles
$user->assignRole('admin'); $user->assignRole('editor', 'moderator'); // multiple
Check roles & permissions
$user->hasRole('admin'); // true/false $user->hasAnyRole(['admin', 'editor']); $user->hasPermissionTo('manage-users');
Protect routes with middleware
Route::middleware(['auth', 'verified', 'role:admin'])->group(function () { Route::get('/admin', [AdminController::class, 'index']); });
Blade directives
@role('admin') <p>Welcome, Administrator!</p> @endrole @permission('manage-users') <a href="/users">Manage Users</a> @endpermission
Configuration
After publishing, edit config/simplerbac.php:
return [ 'user_model' => App\Models\User::class, 'default_role' => 'user', 'redirect_after_login' => '/dashboard', 'email_verification' => true, ];
zohaib482/laravel-simple-rbac 适用场景与选型建议
zohaib482/laravel-simple-rbac 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zohaib482/laravel-simple-rbac 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zohaib482/laravel-simple-rbac 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-13