PHPackages                             ajimoti/roles-and-permissions - 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. ajimoti/roles-and-permissions

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

ajimoti/roles-and-permissions
=============================

Implement roles and permissions on your laravel application, supports many-to-many relationship (pivot tables).

1.1.2(4y ago)621.3k7[2 PRs](https://github.com/ajimoti/roles-and-permissions/pulls)MITPHPPHP ^8.0CI passing

Since Jan 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/ajimoti/roles-and-permissions)[ Packagist](https://packagist.org/packages/ajimoti/roles-and-permissions)[ Docs](https://github.com/ajimoti/roles-and-permissions)[ GitHub Sponsors](https://github.com/ajimoti)[ RSS](/packages/ajimoti-roles-and-permissions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (9)Used By (0)

Simple Laravel roles and permissions
====================================

[](#simple-laravel-roles-and-permissions)

[![Banner](https://camo.githubusercontent.com/b6ae720bf0d9fa71084ef2f5c912569cf7096a9557b1071ca48f89553401f036/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f53696d706c652532304c61726176656c253230526f6c6573253230616e642532305065726d697373696f6e732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616a696d6f7469253246726f6c65732d616e642d7065726d697373696f6e73267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d41737369676e2b726f6c65732b616e642b7065726d697373696f6e2b746f2b6c61726176656c2b6d6f64656c266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/b6ae720bf0d9fa71084ef2f5c912569cf7096a9557b1071ca48f89553401f036/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f53696d706c652532304c61726176656c253230526f6c6573253230616e642532305065726d697373696f6e732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d616a696d6f7469253246726f6c65732d616e642d7065726d697373696f6e73267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d41737369676e2b726f6c65732b616e642b7065726d697373696f6e2b746f2b6c61726176656c2b6d6f64656c266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

Introduction
------------

[](#introduction)

This package allows you to assign roles and permissions to any laravel model, or on a pivot table (`many to many relationship`).

Built and written by [Ajimoti John](https://www.linkedin.com/in/john-ajimoti-3420a786/)

Documentation
-------------

[](#documentation)

You can read the proper [documentation here](https://roles-and-permissions-documentation-two.vercel.app/docs/intro)

Quick Samples
-------------

[](#quick-samples)

### On a Model

[](#on-a-model)

The example below explains how to use the package on a model after installation.

```
use App\Enums\Role;
use App\Enums\Permission;

// Assign a 'Super Admin' role to this user
$user->assign(Role::SuperAdmin);

// Check if the user has the role
$user->hasRole(Role::SuperAdmin);
// Or
$user->isSuperAdmin(); // returns true

// Check if the user can perform a operation
$user->can(Permission::DeleteTransactions);
// Or
$user->canDeleteTransactions();

// Check if the user has multiple permissions
$user->holds(Permission::DeleteTransactions, Permission::BlockUsers);
```

### Pivot table (many to many relationship)

[](#pivot-table-many-to-many-relationship)

This demonstrates how to use the package on a `many to many` relationship. In this example, we assume we have a `merchant` relationship in our `User` model. And this relationship returns an instance of Laravel's `BelongsToMany` class.

Import the `App\Enums\Role` and `App\Enums\Permission` class.

```
use App\Enums\Role;
use App\Enums\Permission;

// Sample merchant
$merchant = Merchant::where('name', 'wallmart')->first();

// Assign a 'Super Admin' role to this user on the selected merchant (wallmart)
$user->of($merchant)->assign(Role::SuperAdmin);

// Check if the user has a super admin role on the selected merchant (wallmart)
$user->of($merchant)->hasRole(Role::SuperAdmin);

// Check if the user can 'delete transactions' on the selected merchant (wallmart)
$user->of($merchant)->can(Permission::DeleteTransactions);

// Check if the user has multiple permissions on the selected merchant (wallmart)
$user->of($merchant)->holds(Permission::DeleteTransactions, Permission::BlockUsers);
```

> > We used the `user` model to make the example explanatory, similar to the examples above the package will work on any model class.

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 8.0 or higher
- Upon installation, the package publishes a `config/roles-and-permissions.php` file, ensure you do not have a file with the same name in your config directory.

### Pros

[](#pros)

- The package can be used on any model, i.e any model can be assigned roles, and permissions.
- Roles can be given multiple permissions.
- Models have permissions via roles.
- Models can be assigned multiple roles.
- A `many to many` relationship can be assigned roles. (i.e the package can be used on a pivot table).
- Supports role hierarchy. (A higher level role can be configured to have the permissions of lower level roles).

### Crons

[](#crons)

- Permissions cannot be assigned directly on a `many to many` relationship.

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

[](#installation)

You can install the package via composer:

```
composer require ajimoti/roles-and-permissions
```

If you have existing pivot tables that you want to apply the package on, you can add the table names to the `pivot.tables` array in the `config/roles-and-permissions.php` config file. The command below will add a `role` column to every pivot table provided in the array.

Run the command below, then you are set to use the package.

```
php artisan roles:install
```

Documentation
-------------

[](#documentation-1)

Visit [documentation here](https://roles-and-permissions-documentation-two.vercel.app/docs/intro) to better understand how to use the package.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [ajimoti](https://github.com/ajimoti)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~4 days

Total

4

Last Release

1569d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00ffaaace8a05e5cf8a3db80ff57db4d65798f9f0d0468a18c893610ea9e87bf?d=identicon)[ajimoti](/maintainers/ajimoti)

---

Top Contributors

[![ajimoti](https://avatars.githubusercontent.com/u/26599467?v=4)](https://github.com/ajimoti "ajimoti (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")

---

Tags

laravellaravel-packagerolesroles-managementroles-permission-managementlaravelroles-and-permissionsajimoti

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ajimoti-roles-and-permissions/health.svg)

```
[![Health](https://phpackages.com/badges/ajimoti-roles-and-permissions/health.svg)](https://phpackages.com/packages/ajimoti-roles-and-permissions)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[jeffgreco13/filament-breezy

A custom package for Filament with login flow, profile and teams support.

1.0k1.7M41](/packages/jeffgreco13-filament-breezy)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[spatie/laravel-passkeys

Use passkeys in your Laravel app

444494.4k16](/packages/spatie-laravel-passkeys)

PHPackages © 2026

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