A Laravel package for managing roles and permissions with Vue 3 UI built on top of Spatie Laravel Permission
abdallahk/laravel-role-manager is a Laravel package for a laravel package for managing roles and permissions with vue 3 ui built on top of spatie laravel permission.
It currently has 8 GitHub stars and 4 downloads on Packagist (latest version v1.0).
Install it with composer require abdallahk/laravel-role-manager.
Discover more Laravel packages by abdallahk
or browse all Laravel packages to compare alternatives.
Last updated
A comprehensive Laravel package for managing roles and permissions with a beautiful Vue 3 user interface. Built on top of the powerful Spatie Laravel Permission package, this package provides an intuitive web interface for managing your application's authorization system.
Install the package via Composer:
composer require abdallahk/laravel-role-manager
Run the installation command:
php artisan role-manager:install
This command will:
Run the migrations:
php artisan migrate
Add the HasRoles trait to your User model:
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
// ... rest of your User model
}
The package publishes a configuration file at config/role-manager.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Route Configuration
|--------------------------------------------------------------------------
*/
'route_prefix' => 'role-manager',
'middleware' => ['web', 'auth'],
/*
|--------------------------------------------------------------------------
| UI Configuration
|--------------------------------------------------------------------------
*/
'ui' => [
'title' => 'Role Manager',
'theme' => 'default',
'per_page' => 15,
],
/*
|--------------------------------------------------------------------------
| Models Configuration
|--------------------------------------------------------------------------
*/
'models' => [
'user' => \App\Models\User::class,
],
];
After installation, visit /role-manager to access the role management interface.
The dashboard provides an overview of your authorization system:
You can assign permissions to roles in two ways:
The interface provides common permission examples like:
manage usersedit postsview reportsmanage settingsThe Users section shows all users with their assigned roles.
The package also provides programmatic access to all functionality:
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
// Create a role
$role = Role::create(['name' => 'editor']);
// Assign permissions to role
$role->givePermissionTo('edit posts', 'delete posts');
// Or sync permissions
$role->syncPermissions(['edit posts', 'delete posts', 'view posts']);
// Create permissions
Permission::create(['name' => 'edit posts']);
Permission::create(['name' => 'delete posts']);
Permission::create(['name' => 'manage users']);
use App\Models\User;
$user = User::find(1);
// Assign role
$user->assignRole('editor');
// Assign multiple roles
$user->assignRole(['editor', 'moderator']);
// Sync roles (removes other roles)
$user->syncRoles(['editor']);
// Remove role
$user->removeRole('editor');
// Check if user has permission
if ($user->can('edit posts')) {
// User can edit posts
}
// Check if user has role
if ($user->hasRole('editor')) {
// User is an editor
}
// Check if user has any of the given roles
if ($user->hasAnyRole(['editor', 'admin'])) {
// User is either editor or admin
}
Use Spatie's middleware to protect routes:
// In your routes file
Route::middleware(['role:admin'])->group(function () {
Route::get('/admin/dashboard', [AdminController::class, 'dashboard']);
});
Route::middleware(['permission:manage users'])->group(function () {
Route::resource('users', UserController::class);
});
Use blade directives in your templates:
@role('admin')
<p>This is visible to users with the admin role.</p>
@endrole
@hasrole('admin')
<p>This is visible to users with the admin role.</p>
@endhasrole
@permission('edit posts')
<p>This is visible to users with the edit posts permission.</p>
@endpermission
@hasanyrole('admin|moderator')
<p>This is visible to users with admin or moderator roles.</p>
@endhasanyrole
The package uses Tailwind CSS. You can customize the appearance by:
php artisan vendor:publish --tag=role-manager-views
resources/views/vendor/role-manager/You can customize the route prefix and middleware in the configuration file:
'route_prefix' => 'role-manager',
'middleware' => ['web', 'auth', 'role:admin'],
Customize how many items are shown per page:
'ui' => [
'per_page' => 25, // Default: 15
],
The package routes are protected by the middleware defined in the configuration. By default, this includes:
web - Web middleware groupauth - Authentication requiredConsider adding role-based middleware:
'middleware' => ['web', 'auth', 'role:admin'],
All forms use Laravel's validation and mass assignment protection.
All forms include CSRF protection via Inertia.js.
Contributions are welcome! Please feel free to submit a Pull Request.
composer install && npm installcomposer testnpm run buildcomposer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.
If you discover any security vulnerabilities, please send an e-mail to the package maintainer.
For general support and questions, please use the GitHub issues page.
Laravel Role Manager - Making role and permission management beautiful and intuitive! π