Search by

shadrackjm / rampart

shadrackmballah

Roles & permissions for the Laravel Livewire starter kit. One command, Flux free, beautiful by default.

Package info

github.com/shadrackjm/rampart

pkg:composer/shadrackjm/rampart

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-18 09:31 UTC

This package is auto-updated.

Last update: 2026-11-18 09:46:30 UTC


README

Rampart

Roles & permissions for the Laravel Livewire starter kit.
One command. Flux free. Beautiful by default.

Latest version Tests Downloads MIT

Rampart: editing the permission matrix and fixing a denied permission with one click

You started a project with laravel new --livewire. Sooner or later someone asks "can the cashier see profit margins?" — and you need roles. Rampart adds a complete, good-looking roles & permissions section to the starter kit in one command, built on spatie/laravel-permission and the free version of Flux.

composer require shadrackjm/rampart
php artisan rampart:install

That's it. Open /rampart as the user you picked.

Why Rampart

  • Made for the starter kit. The installer adds HasRoles to your User, a link to your sidebar and a line to your app.css — and asks before touching each file. The screens use the same layout, Flux components, light and dark mode as the rest of your app.
  • Flux free only. No Flux Pro licence needed.
  • "Why can they?" Pick a person and a permission. Rampart asks your app's real Gate, then shows exactly where the answer comes from — a role, a direct permission, the super admin bypass, or your own Gate rule — and offers a one-click fix when access is denied. Also on the command line: php artisan rampart:why amina@example.com invoices.approve.
  • You cannot lock yourself out. Every change runs in a transaction and is rolled back if it would leave no super admin, or remove your own access to Rampart. The super admin role can't be deleted or renamed.
  • Permissions live in code. Declare them in config/rampart.php (arrays or a backed enum), run rampart:sync in your deploy script, and every environment matches.
  • A matrix that doesn't fight you. Every role against every permission, grouped by area, with search, whole-row and whole-group toggles. Clicking is instant and free — nothing is saved until you press Save, and the save is all-or-nothing.
  • Audit log. Who changed what, when, with a readable diff (+ invoices.approve, − sales.refund).
  • Locked down properly. Every screen and every Livewire request re-checks access — not just the first page load.
  • Tested. 70+ Pest tests covering every safety rule, every screen and the installer's file patches.

Requirements

PHP 8.3+
Laravel 12 or 13
Livewire 4
Flux 2 (free)
spatie/laravel-permission 8

Built for the official Livewire starter kit. Other Livewire + Flux apps work too — see Manual install.

Installation

composer require shadrackjm/rampart
php artisan rampart:install
npm run build

The installer:

  1. publishes Spatie's config and migration (if you don't have them) and Rampart's migration,
  2. publishes config/rampart.php,
  3. adds HasRoles to app/Models/User.php,
  4. adds a Roles & permissions link to resources/views/layouts/app/sidebar.blade.php, visible only to people who may manage access,
  5. adds Rampart's views to Tailwind's @source in resources/css/app.css,
  6. runs the migrations, creates the super-admin role and asks who gets it.

It is safe to run again: steps already done are skipped. Use --force to accept every step, --user=you@example.com to pick the super admin without a prompt, and --no-migrate to skip migrations.

Declaring permissions

// config/rampart.php
'permissions' => [
    'invoices' => ['view', 'create', 'approve' => 'Mark a supplier invoice ready to pay'],
    'reports'  => ['view', 'export', 'profit'],
],

That declares invoices.view, invoices.create, invoices.approve (with a description shown in the panel), and so on. The part before the dot is the group in the matrix.

Prefer an enum? Use a string-backed one; label() and description() are optional:

enum Permission: string
{
    case ApproveInvoices = 'invoices.approve';
    case ExportReports = 'reports.export';

    public function label(): string { /* … */ }
}

// config/rampart.php
'permissions' => [App\Enums\Permission::class],

Then sync — locally, and in your deploy script:

php artisan rampart:sync          # create what's missing, report the rest
php artisan rampart:sync --prune  # also delete permissions no longer declared

Permissions added from the panel instead of code are marked db only, so drift is easy to spot.

Checking permissions

Rampart doesn't invent a new API. Spatie registers every permission on Laravel's Gate, so use what you already know:

// Livewire 4 action
#[Authorize('invoices.approve')]
public function approve(Invoice $invoice) { /* … */ }

// Anywhere
$user->can('reports.export');
Gate::authorize('invoices.approve');
@can('reports.export')
    <flux:button icon="arrow-down-tray">Export</flux:button>
@endcan

The super admin passes every check (super_admin.bypass_gate), so you never need to tick every box for them.

The screens

Roles Cards with user and permission counts. Create (optionally starting from another role's permissions), edit, colour, clone, delete.
Matrix Roles × permissions, grouped. Search, toggle a row or a whole group, see unsaved changes, save once.
Permissions Grouped list showing what's declared in code, what's database-only, and how many roles use each. Sync from code with one button.
Users Search and filter by role. Assign roles and, for exceptions, direct permissions.
Why can they? Verdict, reasons and one-click fix, plus everything a person can do and where each permission comes from.
Audit log Every change, who made it and what changed. Filter by roles, users or permissions.

Commands

Command
rampart:install Install into a starter kit app.
rampart:sync {--prune} Make the database match the permissions in code.
rampart:why {user} {permission} Explain a verdict. Exits non-zero when denied, so it works in scripts.
rampart:super-admin {user} Give someone the super admin role. Your way back in if you're ever locked out.

Configuration

Everything lives in config/rampart.php:

Key Default
path rampart URL prefix of the panel.
middleware ['web', 'auth', 'verified'] Route middleware. The manage permission is always added on top.
layout layouts::app Blade layout the screens render in.
super_admin.role super-admin Name of the all-access role.
super_admin.bypass_gate true Super admins pass every Gate check.
manage_permission rampart.manage Permission that opens the panel for everyone else.
protected_roles [] Roles that can't be renamed or deleted (the super admin role always is).
user_model auth provider's model Model that uses HasRoles.
user_name_column / user_search_columns name / ['name', 'email'] What the user screens show and search.
guard web Guard roles and permissions belong to.
permissions [] Permissions declared in code.
audit.enabled true Record changes.

Want to change a screen? php artisan vendor:publish --tag=rampart-views.

Manual install

Not on the starter kit? Do what the installer does:

  1. php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider", then php artisan vendor:publish --tag=rampart-migrations and php artisan migrate.
  2. Add Spatie\Permission\Traits\HasRoles to your user model.
  3. Add @source '../../vendor/shadrackjm/rampart/resources/views'; to your Tailwind CSS entry.
  4. Set rampart.layout to a layout that renders {{ $slot }} and includes @fluxScripts and a <flux:toast />.
  5. php artisan rampart:sync and php artisan rampart:super-admin you@example.com.

Safety rules

Rampart re-checks these after every change, against the real database state, and rolls the change back if one breaks:

  • There is always at least one user with the super admin role.
  • The person making a change can still open Rampart afterwards.

On top of that, protected roles can't be renamed or deleted, permissions declared in code can only be removed from code, and matrix and user saves are all-or-nothing.

Testing

composer test

Roadmap

  • Spatie teams support in the screens
  • Revert a change from the audit log
  • Import / export roles as JSON
  • Laravel Boost guidelines so AI assistants know how to use Rampart

Ideas and pull requests are welcome.

Credits

License

MIT. See LICENSE.md.