PHPackages                             farbesdev/laravel-ronin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. farbesdev/laravel-ronin

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

farbesdev/laravel-ronin
=======================

A simple and flexible package for managing roles and permissions in Laravel. It efficiently controls access to routes and views using an ACL-based system.

v1.0(yesterday)01↑2900%MITPHP ^8.2

Since Jul 19Compare

[ Source](https://github.com/farbesdev/laravel-ronin)[ Packagist](https://packagist.org/packages/farbesdev/laravel-ronin)[ RSS](/packages/farbesdev-laravel-ronin/feed)WikiDiscussions Synced today

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel Ronin
=============

[](#laravel-ronin)

[![Source](https://camo.githubusercontent.com/08a1ffaf6960497ea699fc845b667aec0b0bf6ee17c309532346029036b0c10c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6661726265736465762f6c61726176656c2d2d726f6e696e2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/farbesdev/laravel-ronin)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)

Note

**Origin Notice**: This package is an independent fork, completely redesigned and modernized, based on the discontinued [caffeinated/shinobi](https://github.com/caffeinated/shinobi) package created by Shea Lewis. We thank the original author for laying the groundwork for this system.

A simple, lightweight, and highly efficient role-based permission system for Laravel's native Authorization Gate. Fully optimized for high-concurrency environments using hybrid in-memory and Redis caching.

- Each user can have zero or more permissions.
- Each user can have zero or more roles.
- Each role can have zero or more permissions.
- Each role can have one of two special flags: `all-access` (grants all access) and `no-access` (denies all permissions).
- **High-Performance Caching**: Powered by request-level local memory caching and granular keys in Redis.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require farbesdev/laravel-ronin
```

### 1. Publish Configuration

[](#1-publish-configuration)

To publish the configuration file, run:

```
php artisan vendor:publish --provider="Ronin\ShinobiServiceProvider" --tag="config"
```

This will create a `config/ronin.php` file in your application.

### 2. Run Migrations

[](#2-run-migrations)

Run the migrations to create the roles, permissions, and corresponding pivot tables:

```
php artisan migrate
```

---

Configuration
-------------

[](#configuration)

In `config/ronin.php`, you can customize your caching strategy to suit your scalability requirements:

```
'cache' => [
    // Enable or disable cross-request caching (e.g., using Redis)
    'enabled' => env('RONIN_CACHE_ENABLED', false),

    // Enable local in-memory caching for the current HTTP request
    'request_memory' => true,

    // Enable granular cache per user/role instead of caching the entire permissions table
    'granular' => true,

    // Cache TTL in seconds (defaults to 24 hours)
    'length' => 86400,

    // Prefix used for cache keys in Redis
    'prefix' => 'ronin',
],
```

---

Cache Architecture
------------------

[](#cache-architecture)

Laravel Ronin includes a hybrid caching mechanism:

1. **Request-Level Cache**: Stores role/permission validation results in static memory for the current HTTP request. Even if the persistent cache is disabled, this ensures that multiple checks for the same user execute exactly **zero database queries**.
2. **Granular Cache in Redis**: Instead of saving the entire permissions database (which degrades performance as data volume grows), Ronin segments the keys:
    - `ronin:user:{id}:roles` -&gt; Stores user roles.
    - `ronin:user:{id}:permissions` -&gt; Stores direct user permissions.
    - `ronin:role:{id}:permissions` -&gt; Stores role permissions.
3. **Smart Invalidation**: When modifying relationships via `assignRoles`, `removeRoles`, `givePermissionTo`, `syncPermissions`, etc., only the specific affected keys are invalidated.

---

Usage
-----

[](#usage)

### Model Configuration

[](#model-configuration)

Add the `HasRolesAndPermissions` trait to your `User` model:

```
use Ronin\Concerns\HasRolesAndPermissions;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasRolesAndPermissions;
}
```

### Assigning Roles and Permissions

[](#assigning-roles-and-permissions)

```
// Assigning roles
$user->assignRoles('admin');
$user->removeRoles('admin');
$user->syncRoles(['editor', 'moderator']);

// Granting permissions
$user->givePermissionTo('edit.posts');
$user->revokePermissionTo('edit.posts');
$user->syncPermissions(['edit.posts', 'delete.posts']);
```

### Permission Validation

[](#permission-validation)

Use Laravel's native Gate or the model's methods:

```
// Using native Gates
if (Gate::allows('edit.posts')) {
    // ...
}

// User model methods
if ($user->hasPermissionTo('edit.posts')) {
    // ...
}

if ($user->hasRole('admin')) {
    // ...
}
```

### Blade Directives

[](#blade-directives)

```
@can('edit.posts')

@endcan

@role('admin')

@endrole

@anyrole('editor', 'moderator')

@endanyrole

@allroles('editor', 'moderator')

@endallroles
```

### Middleware Protection

[](#middleware-protection)

You can protect your routes with the included middlewares:

```
Route::group(['middleware' => ['role:admin']], function () {
    // Routes protected by role
});

Route::group(['middleware' => ['permission:edit.posts']], function () {
    // Routes protected by permission
});
```

---

Testing
-------

[](#testing)

Run the test suite with PHPUnit:

```
composer test
```

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](LICENSE.md).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d3402cc7e536f7da60c7f90c0251fa32d6bbfb398dce1c546e38bc847f344d3?d=identicon)[farbesdev](/maintainers/farbesdev)

---

Tags

laravelauthrolespermissionsroninlaravel-ronin

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/farbesdev-laravel-ronin/health.svg)

```
[![Health](https://phpackages.com/badges/farbesdev-laravel-ronin/health.svg)](https://phpackages.com/packages/farbesdev-laravel-ronin)
```

###  Alternatives

[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6765.1k6](/packages/hasinhayder-tyro)[phpzen/laravel-rbac

Role based access control for Laravel 5

383.2k](/packages/phpzen-laravel-rbac)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
