PHPackages                             whilesmart/eloquent-roles - 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. whilesmart/eloquent-roles

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

whilesmart/eloquent-roles
=========================

Flexible roles and permissions package for Laravel applications

v1.0.1(2mo ago)2666↑75%1[1 PRs](https://github.com/whilesmartphp/eloquent-roles/pulls)2MITPHPPHP ^8.2CI passing

Since Sep 10Pushed 2mo agoCompare

[ Source](https://github.com/whilesmartphp/eloquent-roles)[ Packagist](https://packagist.org/packages/whilesmart/eloquent-roles)[ RSS](/packages/whilesmart-eloquent-roles/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (13)Used By (2)

Whilesmart Eloquent Roles
=========================

[](#whilesmart-eloquent-roles)

A flexible roles and permissions package for Laravel applications built on Eloquent ORM.

[![Latest Version on Packagist](https://camo.githubusercontent.com/08552d0d9a63fdfa230fa994fe0ab62328a95c49c6939fe92711e8362e930941/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7768696c65736d6172742f656c6f7175656e742d726f6c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/whilesmart/eloquent-roles)

Features
--------

[](#features)

- **Contextual Roles**: Assign roles within specific contexts (e.g., user can be admin in one workspace, member in another)
- **Hierarchical Permissions**: Role-based permissions with inheritance support
- **Eloquent Integration**: Seamlessly integrates with your existing Eloquent models
- **Flexible Architecture**: Support for abilities, permissions, and role assignments
- **Laravel Auto-Discovery**: Automatically registers service provider

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

[](#installation)

Install the package via Composer:

```
composer require whilesmart/eloquent-roles
```

The package will automatically register its service provider.

Usage
-----

[](#usage)

### Adding Roles to Models

[](#adding-roles-to-models)

Use the `HasRoles` trait on any model that should have roles:

```
use Whilesmart\Roles\Traits\HasRoles;

class User extends Model
{
    use HasRoles;
}
```

### Role Management

[](#role-management)

```
// Check if user has a role
$user->hasRole('admin');

// Check role within specific context
$user->hasRole('manager', 'workspace', $workspaceId);

// Assign role
$user->assignRole($role);

// Assign role with context
$user->assignRole($role, 'workspace', $workspaceId);
```

### Permission Management

[](#permission-management)

Use the `HasPermissions` trait for permission-based access control:

```
use Whilesmart\Roles\Traits\HasPermissions;

class User extends Model
{
    use HasRoles, HasPermissions;
}
```

```
// Check permissions
$user->hasPermission('edit-posts');
$user->hasPermission('manage-users', 'workspace', $workspaceId);
```

Models
------

[](#models)

### Role

[](#role)

- **name**: Human-readable role name
- **slug**: URL-friendly identifier (auto-generated)
- **description**: Role description
- **level**: Hierarchical level for role inheritance

### Permission

[](#permission)

- **name**: Permission name
- **slug**: URL-friendly identifier
- **description**: Permission description

### RoleAssignment

[](#roleassignment)

- **assignable**: Polymorphic relation to any model
- **role\_id**: Associated role
- **context\_type**: Context model type (optional)
- **context\_id**: Context model ID (optional)

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

[](#configuration)

The package works out of the box, but you can customize it by publishing the configuration:

```
php artisan vendor:publish --provider="Whilesmart\Roles\RolesServiceProvider"
```

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

[](#requirements)

- PHP ^8.2
- Laravel ^11.0|^12.0

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance86

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~154 days

Total

2

Last Release

74d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1ca6f6e01ecbfe6640ff410c4f0321054fb48d05a5f843c2b89887b90369bcd?d=identicon)[whilesmart](/maintainers/whilesmart)

---

Top Contributors

[![nfebe](https://avatars.githubusercontent.com/u/14317775?v=4)](https://github.com/nfebe "nfebe (11 commits)")[![kofimokome](https://avatars.githubusercontent.com/u/21100923?v=4)](https://github.com/kofimokome "kofimokome (10 commits)")[![iMercyvlogs](https://avatars.githubusercontent.com/u/111022500?v=4)](https://github.com/iMercyvlogs "iMercyvlogs (1 commits)")

---

Tags

phplaravelpackagerolespermissionsrbac

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/whilesmart-eloquent-roles/health.svg)

```
[![Health](https://phpackages.com/badges/whilesmart-eloquent-roles/health.svg)](https://phpackages.com/packages/whilesmart-eloquent-roles)
```

###  Alternatives

[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)[hasinhayder/tyro

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

6712.1k2](/packages/hasinhayder-tyro)[smarch/watchtower

Front-end for the Shinboi Auth system of Users / Roles / Permissions in Laravel 5

523.0k](/packages/smarch-watchtower)

PHPackages © 2026

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