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

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

putheng/role
============

A role and permission package for Laravel

1.1(7y ago)025PHPPHP &gt;=7.0

Since Jan 28Pushed 7y ago1 watchersCompare

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

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

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

[](#installation)

Require this package with composer.

```
composer require putheng/role

```

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

### Setting up from scratch

[](#setting-up-from-scratch)

#### Laravel 5.5+:

[](#laravel-55)

If you don't use auto-discovery, add the ServiceProvider to the providers array in `config/app.php`

```
Putheng\Role\RoleServiceProvider::class,
```

#### The schema

[](#the-schema)

For Laravel 5 migration

```
php artisan migrate
```

#### The model

[](#the-model)

Your model should use `Putheng\Role\Traits\HasPermissionsTrait` trait to User model:

```
use Putheng\Role\Traits\HasPermissionsTrait;

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

#### Add to `AppServiceProvider` on `boot` method for Bootstrap services.

[](#add-to-appserviceprovider-on-boot-method-for-bootstrap-services)

```
use Putheng\Role\Models\Permission;

Permission::get()->map(function($permission){
    Gate::define($permission->name, function($user) use ($permission){
        return $user->hasPermissionTo($permission);
    });
});
```

#### Middleware

[](#middleware)

Add `RoleMiddleware` to `$routeMiddleware` in `App\Http\Kernel` class

```
'role' => \Putheng\Role\RoleMiddleware::class,
```

##### Router

[](#router)

```
Route::group(['middleware' => 'role:admin'], function () {
    Route::group(['middleware' => 'role:admin,delete users'], function () {
        Route::get('/admin/users', function () {
            return 'Delete users in admin panel';
        });
    });

    Route::get('/admin', function () {
        return 'Admin panel';
    });
});
```

Usage
-----

[](#usage)

Check is user has roles

```
$user = User::find(1);

// multiple argument
$user->hasRole('admin', 'user');
// true or false
```

Give role to

```
$user = User::find(1);

// multiple argument
$user->giveRoleTo('admin', 'user');
// true or false
```

Refresh role

```
$user = User::find(1);

// multiple argument
$user->refreshRoles('admin', 'user');
// true or false
```

Check is user has permission or permission through role

```
$user = User::find(1);

$user->hasPermissionTo('edit posts', 'delete posts');
// true or false

// Use Laravel Gate can method
$user->can('edit posts');
```

Give permissions

```
$user = User::find(1);

$user->givePermissionTo(['edit posts', 'delete posts']);
```

Revoke permissions

```
$user = User::find(1);

$user->withdrawPermissionTo(['edit posts']);
```

Refresh permissions remove all user's permissions and re-give the permissions

```
$user = User::find(1);

$user->refreshPermissions(['edit posts']);
```

Custom blade what we output inside template Role

```
@role('admin')
    Admin panel
@endrole
```

Permission

```
@permission('edit post')
    Edit post
@endpermission
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

2

Last Release

2662d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a517c33df877331a2ef37a0b9bfef3ffed53756b3ebb3c33f4a8713c075a9ec?d=identicon)[putheng](/maintainers/putheng)

---

Top Contributors

[![putheng](https://avatars.githubusercontent.com/u/19757130?v=4)](https://github.com/putheng "putheng (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[yajra/laravel-acl

Laravel ACL is a simple role, permission ACL for Laravel Framework.

112103.9k1](/packages/yajra-laravel-acl)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)

PHPackages © 2026

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