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

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

ahrengot/laravel-roles-and-permissions
======================================

User roles and permissions for Laravel

2.0.0(1y ago)01.8k↓38.9%MITPHPPHP ^8.1CI passing

Since Aug 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Ahrengot/laravel-roles-and-permissions)[ Packagist](https://packagist.org/packages/ahrengot/laravel-roles-and-permissions)[ Docs](https://github.com/Ahrengot/laravel-roles-and-permissions)[ RSS](/packages/ahrengot-laravel-roles-and-permissions/feed)WikiDiscussions main Synced 3w ago

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

User roles and permissions for Laravel
======================================

[](#user-roles-and-permissions-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e43a647bf73231964eedb7d02f49e08baacc83bf25b9292292439d2c8cbfb94f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616872656e676f742f6c61726176656c2d726f6c65732d616e642d7065726d697373696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahrengot/laravel-roles-and-permissions)[![GitHub Tests Action Status](https://camo.githubusercontent.com/cc8626f657e9199022f40d234bc09f17093007e1b3f0a43b76ddfa99b381ac2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416872656e676f742f6c61726176656c2d726f6c65732d616e642d7065726d697373696f6e732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/Ahrengot/laravel-roles-and-permissions/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d63e21d59339e235032e34c9e6486c6b4b6648adc42a9d7051b8cd45c49f1bb5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416872656e676f742f6c61726176656c2d726f6c65732d616e642d7065726d697373696f6e732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/Ahrengot/laravel-roles-and-permissions/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/cd5918f343096f37df0ba144142546c6ce67ce57623d1e0ec1b2e158385d2538/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616872656e676f742f6c61726176656c2d726f6c65732d616e642d7065726d697373696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahrengot/laravel-roles-and-permissions)

Roles and permissions for laravel

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

[](#installation)

Install the package via composer

```
composer require ahrengot/laravel-roles-and-permissions
```

Run the install command to publish the migration, stubs, config file and a basic test

```
php artisan roles-and-permissions:install
```

Run the migration to add a `role` column to your users table. Feel free to modify this migration as needed.

```
php artisan migrate
```

Configuring your User model
---------------------------

[](#configuring-your-user-model)

Add the `HasPermissions` trait to your user model and an enum cast for the role column. Optionally you can add a default value for the role using the built-in `$attributes` property.

```
use \Ahrengot\RolesAndPermissions\Traits\HasPermissions;
use App\Enums\UserRole;

class User extends Authenticatable
{
    use HasPermissions;

    protected $casts = [
        'role' => UserRole::class,
    ];

    // Optional default role
    protected $attributes = [
        'role' => UserRole::User,
    ]
}
```

Configuring roles and permissions
---------------------------------

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

Your permissions are configured in `config/permissions.php`.

User roles are defined in `App\Enums\UserRole.php`. Update these roles to fit your application needs.

Permissions are just simple strings, but this package provides a helper class in `App/Permissions/Permission.php` that declare each permission as a constant. This provides better editor support and helps prevent typos.

The config file contains an example of defining various permissions for each user role:

```
return [
    'roles' => [
        UserRole::Admin->value => [
            Permission::AccessAdminPanel,
            Permission::CreateApiTokens,
        ],
    ],
];
```

Usage
-----

[](#usage)

In blade

```

    @can(Permission::AccessAdminPanel)
        Admin panel
    @endcan
    Other link

```

In policies

```
public function create(User $user)
{
    return $user->can(Permission::CreatePosts);
}
```

Comparing user roles
--------------------

[](#comparing-user-roles)

The UserRole enum has two comparison methods

```
    $user->role->is(UserRole::Admin);

    $user->role->isNot(UserRole::Admin);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [Jens Ahrengot Boddum](https://github.com/Ahrengot)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance47

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% 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 ~335 days

Total

3

Last Release

390d ago

Major Versions

1.0.1 → 2.0.02025-06-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/38c85f21d9150e32ca0871a5e7c7f06e2f91374eb0d9bc1854c3e5d207467d41?d=identicon)[ahrengot](/maintainers/ahrengot)

---

Top Contributors

[![Ahrengot](https://avatars.githubusercontent.com/u/391810?v=4)](https://github.com/Ahrengot "Ahrengot (44 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelpermissionsroleslaravelrolespermissionsahrengot

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

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

Filament support for `spatie/laravel-permission`.

2.8k3.5M118](/packages/bezhansalleh-filament-shield)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[spatie/laravel-passkeys

Use passkeys in your Laravel app

470755.5k32](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[chiiya/filament-access-control

Admin user, role and permission management for Laravel Filament

21851.1k](/packages/chiiya-filament-access-control)

PHPackages © 2026

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