delgont / armor
Armor is a high‑performance Laravel package for managing user roles and permissions. It provides a flexible, cache‑friendly system to define, assign, and enforce permissions across your application, making route and action protection seamless and efficient.
v1.9.1
2026-04-12 19:13 UTC
Requires
- php: ^7.2.5 || ^8.0
- illuminate/auth: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/database: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- laravel/helpers: ^1.5.0 || 1.6.0 || 1.7.0
README
Armor – Laravel Role & Permission Package
Armor is a powerful, flexible, and cache-friendly permission and role management package for Laravel applications. Designed with performance in mind, Armor allows you to define roles and permissions, assign them to users, and protect routes or actions effortlessly.
🔒 Built for speed
⚙️ Highly customizable
📦 Supports permission groups, caching, syncing, and more
Installation
composer require delgont:armor php artisan migrate
Restrict Access Using Permissions
- Create Permission Registrar and Define the permissions.
php artisan make:permissionRegistrar ExpensePermissionRegistrar
<?php namespace App; use Delgont\Armor\PermissionRegistrar; class ExpensePermissionRegistrar extends PermissionRegistrar { const CAN_MANAGE_EXPENSES = 'can_manage_expenses'; const CAN_ADD_EXPENSES = 'can_add_expenses'; /** * Provide descriptions for each permission. * * @return array */ public function descriptions(): array { return [ self::CAN_MANAGE_EXPENSES => 'Allow user to manage expenses', self::CAN_ADD_EXPENSES => 'Allow user to add expenses', ]; } }
- Register Permission Register in your Service Provider.
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Delgont\Armor\Armor; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application servipSycnces. * * @return void */ public function boot() { Armor::registerPermissionRegistrars([ \App\ExpensePermissionRegistrar::class, ]); } }
- Synchronize Permisions.
php artisan armor:sync-permissions
Apply Permissions Directly to the Authenticatable Model
<?php namespace App; use Delgont\Armor\Concerns\ModelHasPermissions; class User extends Authenticatable { use ModelHasPermissions; }
# Geting permissions of specific group $permissions = app(\App\ExpensePermissionRegistrar::class)->getPermissionsFromDb(); # Get model which uses trait Delgont\Armor\Concerns\ModelHasPermissions $user = User::whereId(3)->first(); # Give permissions to user $user->givePermissionTo($permissions); # Withdrawal permissions from user $user->withdrawPermissionsTo($permissions); # Sync permissions from user $user->syncPermissions($permissions); # Check if model|user has permission if($user->hasPermission('can_manage_expenses')) { return 'User has the permission'; } else { return 'User does not have the permission'; } # Check if model has any of the permissions if($user->hasAnyPermission('can_add_expenses', 'can_manage_expenses')) { return 'User has the permission'; } else { return 'User does not have the permission'; } # Protect Routes - Works only for user model which is authenticatable Route::post('/expenses/add', 'ExpenseController@store')->middleware(['permission:can_add_expenses']);
📖 Developed by: Stephen Okello
