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

ActiveLibrary

zorca/roles-and-permissions
===========================

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

1.1.2(4y ago)08031MITPHPPHP ^8.0

Since Jan 12Pushed 3y agoCompare

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

READMEChangelogDependencies (9)Versions (7)Used By (1)

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 Ibukun](https://www.linkedin.com/in/ibukun-ajimoti-3420a786/)

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

[](#documentation)

You can read the proper [documentation here](https://roles.ajimoti.com/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  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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56% of commits — single point of failure

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/2f06417d346331422a76bb8da4506b268bee38ab0707445529238664ca4bbb47?d=identicon)[zorca](/maintainers/zorca)

---

Top Contributors

[![ajimoti](https://avatars.githubusercontent.com/u/26599467?v=4)](https://github.com/ajimoti "ajimoti (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")[![zorca](https://avatars.githubusercontent.com/u/5238179?v=4)](https://github.com/zorca "zorca (2 commits)")

---

Tags

laravelroles-and-permissionsajimoti

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[ajimoti/roles-and-permissions

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

621.3k](/packages/ajimoti-roles-and-permissions)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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