a2zwebltd/nova-role-manager

A Laravel Nova tool for managing Spatie roles and permissions with optional audit logging.

Installs: 86

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/a2zwebltd/nova-role-manager

v1.0.0 2026-01-26 01:59 UTC

This package is auto-updated.

Last update: 2026-01-26 05:56:31 UTC


README

A visual role and permission management tool for Laravel Nova. Built on Spatie's Laravel Permission package with automatic audit logging.

Role Manager Interface

Installation

composer require a2zwebltd/nova-role-manager

Quick Setup

1. Register the Tool

Add to app/Providers/NovaServiceProvider.php:

use A2ZWeb\NovaRoleManager\RoleManager;

public function tools(): array
{
    return [
        new RoleManager,
    ];
}

2. Add new menu item

MenuItem::make(__('Roles and Permissions Manager'))
    ->path('/role-manager')

3. Done!

You can now add permissions with sections / groups like this:

Permission::create([
    'name' => 'viewPosts',
    'group' => 'Content Management / Blogs',
    'guard_name' => 'admin-dashboard',
]);

Demo Data (Optional)

Demo roles and permissions

php artisan db:seed --class="A2ZWeb\NovaRoleManager\Database\Seeders\RoleManagerDemoSeeder"

Demo data includes:

  • admin guard with 3 roles (Admin, Editor, Author) and basic CRUD permissions
  • web guard with 2 roles (Member, Contributor) and user-facing permissions
  • Examples of nested groups (Blog / Posts, Management / Settings / General)
  • Examples of ungrouped permissions (Reports, Beta Features)

What's Included

  • Visual Interface: Table-based permission management across multiple roles
  • Multi-Guard Support: Manage permissions for different guards
  • Permission Grouping: Organize permissions by section/group
  • Optional Audit Logging: Track all role and permission changes (opt-in)
  • Auditable Models: Drop-in replacements for Spatie models with automatic audit tracking

Configuration (Optional)

Publish the config to customize behavior:

php artisan vendor:publish --tag=role-manager-config

Enabling Audit Logging

The package includes auditable models for automatic change tracking. To enable:

1. Set up Laravel Auditing:

# Publish config and migration
php artisan vendor:publish --tag=config --provider="OwenIt\Auditing\AuditingServiceProvider"
php artisan vendor:publish --tag=migrations --provider="OwenIt\Auditing\AuditingServiceProvider"

# Run migration
php artisan migrate

2. Use auditable models in config/role-manager.php:

'role_model' => \A2ZWeb\NovaRoleManager\Models\AuditableRole::class,
'permission_model' => \A2ZWeb\NovaRoleManager\Models\AuditablePermission::class,

3. add a "View Audit Logs" button in config/role-manager.php

'enable_audit_logs' => true,

Permission Checks

Control who can edit roles:

'edit_permission' => 'editRoles',  // Set to null to allow all authenticated users
'view_audit_logs_permission' => 'viewAuditLogs',  // Set to null to allow all

Permission Grouping

For best organization, use forward slashes in the group field:

Permission::create([
    'name' => 'viewUsers',
    'group' => 'Admin Dashboard / Users',
    'guard_name' => 'admin',
]);

Ungrouped Permissions:

Permissions without slashes or empty groups are placed in a catch-all category:

'ungrouped_permissions_category' => 'Other',  // Default category for ungrouped permissions
// 'ungrouped_permissions_category' => null,  // Set to null to hide ungrouped permissions

Advanced

Custom Permission Repository

Override how permissions are fetched:

'permission_repository' => \App\Repositories\MyPermissionRepository::class,

Repository must have allForGuard(string $guardName): Collection method.

Protected Roles

Prevent certain roles from being edited:

'protected_roles' => [
    'SUPER_ADMIN',
],

Guard Display Order

Control tab order:

'guard_order' => [
    'admin-dashboard',
    'user-dashboard',
],

Requirements

  • Laravel 10+
  • Laravel Nova 5+
  • Spatie Laravel Permission 5+
  • PHP 8.1+

License

MIT

Security

If you discover a security vulnerability, please email contact@a2zweb.co.

Credits