Simple and lightweight Role-Based Access Control (RBAC) package for Laravel 11+ and 12 with authentication and email verification support
zohaib482/laravel-simple-rbac is a Laravel package for simple and lightweight role-based access control (rbac) package for laravel 11+ and 12 with authentication and email verification support.
It currently has 2 GitHub stars and 7 downloads on Packagist (latest version v0.2.4).
Install it with composer require zohaib482/laravel-simple-rbac.
Discover more Laravel packages by zohaib482
or browse all Laravel packages to compare alternatives.
Last updated
A simple, lightweight Role-Based Access Control (RBAC) package for Laravel with built-in authentication and email verification support.
role:admin, permission:manage-users, etc.@role, @permission, @anyroleInstall 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
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
}
$user->assignRole('admin');
$user->assignRole('editor', 'moderator'); // multiple
$user->hasRole('admin'); // true/false
$user->hasAnyRole(['admin', 'editor']);
$user->hasPermissionTo('manage-users');
Route::middleware(['auth', 'verified', 'role:admin'])->group(function () {
Route::get('/admin', [AdminController::class, 'index']);
});
@role('admin')
<p>Welcome, Administrator!</p>
@endrole
@permission('manage-users')
<a href="/users">Manage Users</a>
@endpermission
return [
'user_model' => App\Models\User::class,
'default_role' => 'user',
'redirect_after_login' => '/dashboard',
'email_verification' => true,
];