PHPackages                             herode/role - 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. herode/role

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

herode/role
===========

Herode Roles and permissions

0147PHP

Since May 2Pushed 7y ago1 watchersCompare

[ Source](https://github.com/binhnxit/heroderole)[ Packagist](https://packagist.org/packages/herode/role)[ RSS](/packages/herode-role/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Herode Roles and Permissions (Laravel)
======================================

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

Install
-------

[](#install)

Have two options to install, you can choose one of them

### 1. If you want to use and modify this package, You can:

[](#1-if-you-want-to-use-and-modify-this-package-you-can)

- Copy this folder `heroderole` to `modules/heroderole` into your root project
- Open file `composer.json` and edit

```
{
    //...
    "require": {
        "herode/role": "*@dev",
    },
    "repositories": [
        //...
        {
          "type": "path",
          "url": "./modules/heroderole"
        }
      ]
    //...
}

```

### 2. Or you can install via composer

[](#2-or-you-can-install-via-composer)

`composer require herode/role`

Next, run: `composer update`

You can publish the migrations, configure, seeds vie command:
`php artisan herode-role:install`

After the migrations published you can create the roles tables by running the migrations:
`php artisan migrate`

When published, The `config/herode-roles.php` config file contains:

```
return [
    'models' => [
        /*
         * Herode roles model
         */
        'role' => Herode\Role\Role::class,
    ],

    'table_names' => [
        'role' => 'roles'
    ],
];
```

How to use
----------

[](#how-to-use)

First, add the `Herode\Role\Contracts\HasRoles` trait to your `User` model:

```
use Herode\Role\Contracts\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasRoles;
    // ...
}
```

Create a role:

```
$role = Role::create(['name' => 'admin', 'description' => 'Administrator']);
```

A role can be assign from user:

```
$user->assignRole($role);
```

You can check if user has a role:

```
$user->hasRole('admin')
```

Remove role from user:

```
$user->removeRole('admin')
```

You can published role default seeder via seed command:
`php artisan db:seed --class=RoleDefaultSeeder`

Using a middleware
------------------

[](#using-a-middleware)

This package comes with `RoleMiddleware` middleware. You can add them inside your `app/Http/Kernel.php` file:

```
protected $routeMiddleware = [
        //...
        'role' => \Herode\Role\Middlewares\RoleMiddleware::class,
    ];

```

Then you can protect your routes using middleware rules:

```
Route::middleware(['role:admin'])->group(function () {
    //...
});
```

```
Route::middleware(['role:admin|company'])->group(function () {
    //...
});
```

Catching role failures

------------------------

[](#catching-role-failures-)

If you want to override the default 403 response, You can catch the `UnauthorizedException` using your app's exception handler:

```
public function render($request, Exception $exception)
{
    if ($exception instanceof Herode\Role\Exceptions\UnauthorizedException) {
        // Code here ...
    }

    return parent::render($request, $exception);
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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.

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/herode-role/health.svg)

```
[![Health](https://phpackages.com/badges/herode-role/health.svg)](https://phpackages.com/packages/herode-role)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)

PHPackages © 2026

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