shadrackjm / rampart
Roles & permissions for the Laravel Livewire starter kit. One command, Flux free, beautiful by default.
Requires
- php: ^8.3
- illuminate/contracts: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- livewire/flux: ^2.0
- livewire/livewire: ^4.0
- spatie/laravel-permission: ^8.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0|^5.0
- pestphp/pest-plugin-laravel: ^4.0|^5.0
- pestphp/pest-plugin-livewire: ^4.0|^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Roles & permissions for the Laravel Livewire starter kit.
One command. Flux free. Beautiful by default.
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
HasRolesto yourUser, a link to your sidebar and a line to yourapp.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), runrampart:syncin 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:
- publishes Spatie's config and migration (if you don't have them) and Rampart's migration,
- publishes
config/rampart.php, - adds
HasRolestoapp/Models/User.php, - adds a Roles & permissions link to
resources/views/layouts/app/sidebar.blade.php, visible only to people who may manage access, - adds Rampart's views to Tailwind's
@sourceinresources/css/app.css, - runs the migrations, creates the
super-adminrole 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:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider", thenphp artisan vendor:publish --tag=rampart-migrationsandphp artisan migrate.- Add
Spatie\Permission\Traits\HasRolesto your user model. - Add
@source '../../vendor/shadrackjm/rampart/resources/views';to your Tailwind CSS entry. - Set
rampart.layoutto a layout that renders{{ $slot }}and includes@fluxScriptsand a<flux:toast />. php artisan rampart:syncandphp 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
- Shadrack Mballah
- Built on spatie/laravel-permission, Livewire and Flux.
License
MIT. See LICENSE.md.
