PHPackages                             andrey-helldar/laravel-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. andrey-helldar/laravel-roles

Abandoned → [spatie/laravel-permission](/?search=spatie%2Flaravel-permission)ArchivedLibrary[Authentication &amp; Authorization](/categories/authentication)

andrey-helldar/laravel-roles
============================

Simple roles and permissions handling for Laravel

v2.7.1(5y ago)121.7k2MITPHPPHP ^7.1.3|^8.0

Since Apr 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/andrey-helldar/laravel-roles)[ Packagist](https://packagist.org/packages/andrey-helldar/laravel-roles)[ Fund](https://money.yandex.ru/to/410012115955701)[ Fund](https://paypal.me/helldar)[ RSS](/packages/andrey-helldar-laravel-roles/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (11)Versions (35)Used By (0)

Laravel Basic Roles and Permissions
===================================

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

Basic roles and permissions handling for Laravel 5.5 and up.

[![laravel roles](https://user-images.githubusercontent.com/10347617/56795701-ad270f00-6819-11e9-854c-df13a53d1e8c.png)](https://user-images.githubusercontent.com/10347617/56795701-ad270f00-6819-11e9-854c-df13a53d1e8c.png)

This package is abandoned and no longer maintained. The author suggests using the [spatie/laravel-permission](https://github.com/spatie/laravel-permission) package instead.

[![StyleCI Status](https://camo.githubusercontent.com/1248db45eb702f26bb4f0b7c4201b2d2a266ec1ca74836412f8b1b3d086099b9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3138333433363730362f736869656c64)](https://github.styleci.io/repos/183436706)[![Github Workflow Status](https://camo.githubusercontent.com/296266bb581249a57204386cd3563daad240eb97cb3ed94f3bdfed6c9f6afd0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65732f706870756e69743f7374796c653d666c61742d737175617265)](https://github.com/andrey-helldar/laravel-roles/actions)[![Coverage Status](https://camo.githubusercontent.com/c1c661eb8e4025886ec54f151680a1bfd4143b52a36722e13c11ef7add5b33b4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andrey-helldar/laravel-roles/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/39bf1187669ab62fdcc519c8399662071a6f1d1fc792696eb2a4242b3a1f6ca8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andrey-helldar/laravel-roles/?branch=master)[![For Laravel](https://camo.githubusercontent.com/f56fc6470fafc90f71c839bbdb1092cc6ac862c7d218f54d3ad60c96e1db734f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e352b253230253743253230362e78253230253743253230372e78253230253743253230382e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/laravel-roles)

[![Stable Version](https://camo.githubusercontent.com/fad43f382ff9ff05bc30aa7c3802aae45885a4dd0045133596c24ab2aff3529c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65733f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/laravel-roles)[![Unstable Version](https://camo.githubusercontent.com/b842dab29abdb0f93349e795496f472d7748d125ec7b784b03ae526d1ee9aea2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d6d61737465722d6f72616e67653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/laravel-roles)[![Total Downloads](https://camo.githubusercontent.com/6daff4b678988bcf02de65d39b2904c5b65116fbc4ea32af3b9480ba70f22bcd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andrey-helldar/laravel-roles)[![License](https://camo.githubusercontent.com/a201ee3480e4c0b7eda3ba7ee256d1cdb7312392ea99ed88e616f239c0a42bd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616e647265792d68656c6c6461722f6c61726176656c2d726f6c65732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Using](#using)
    - [User model](#user-model)
    - [Middleware](#middleware)
    - [Creating](#creating)
    - [Assign, revoke and sync permissions](#assign-revoke-and-sync-permissions)
        - [Assign permissions](#assign-permissions)
        - [Revoke permissions](#revoke-permissions)
        - [Syncing permissions](#syncing-permissions)
    - [Blade](#blade)
    - [Checking for permissions](#checking-for-permissions)
        - [A `root` role](#a-root-role)
        - [`user` » `role`](#user--role)
        - [`user` » `roles`](#user--roles)
        - [`user` » `permission`](#user--permission)
        - [`user` » `permissions`](#user--permissions)
        - [`role` » `permission`](#role--permission)
        - [`role` » `permissions`](#role--permissions)
    - [Artisan commands](#artisan-commands)
- [License](#license)

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

[](#installation)

> If you upgrade from the old version, you can see the list of changes in the Upgrade Guide:
>
> - [Upgrading To 2.x From 1.x](.upgrade/To_2.x_from_1.x.md)

To get the latest version of `Laravel Roles`, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require andrey-helldar/laravel-roles
```

Or manually update `require` block of `composer.json` and run `composer update`.

```
{
    "require-dev": {
        "andrey-helldar/laravel-roles": "^2.4"
    }
}
```

Now you can publish the configuration and migration file by running the command:

```
php artisan vendor:publish --provider="Helldar\Roles\ServiceProvider"

```

You can create the DB tables by running the migrations:

```
php artisan migrate

```

This command will create such `roles`, `permissions`, `user_role` and `role_permission` tables.

Using
-----

[](#using)

### User model

[](#user-model)

First, add the `Helldar\Roles\Traits\HasRoles` trait to your `User` model:

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use Helldar\Roles\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;

    // ...
}
```

### Middleware

[](#middleware)

You can add middlewares in `$routeMiddleware` of `app/Http/Kernel.php` file:

```
use Helldar\Roles\Http\Middleware\Permission;
use Helldar\Roles\Http\Middleware\Permissions;
use Helldar\Roles\Http\Middleware\Role;
use Helldar\Roles\Http\Middleware\Roles;

protected $routeMiddleware = [
    // ...

    'role'        => Role::class,        // Checks for the entry of one of the specified permissions.
    'roles'       => Roles::class,       // Checks the entry of all of the specified permissions.
    'permission'  => Permission::class,  // Checks for the occurrence of one of the specified roles.
    'permissions' => Permissions::class, // Checks the entry of all of the specified roles.
]
```

Now you can check if one of the conditions is met:

```
// Example, user has been a `foo` role and a `baz` permission

// success access
app('router')
    ->middleware('role:foo,bar', 'permission:foo,bar')
    ->get(...)

// success access
app('router')
    ->middleware('role:foo,bar')
    ->get(...)

// failed access
app('router')
    ->middleware('permission:foo,bar')
    ->get(...)
```

Or check the entry of all conditions:

```
// Example, user has been a `foo` role and a `baz` permission

// failed access
app('router')
    ->middleware('roles:foo,bar', 'permissions:foo,bar')
    ->get(...)

// failed access
app('router')
    ->middleware('roles:foo,bar')
    ->get(...)

// success access
app('router')
    ->middleware('roles:foo')
    ->get(...)

// failed access
app('router')
    ->middleware('permissions:foo,bar')
    ->get(...)

// success access
app('router')
    ->middleware('permissions:baz')
    ->get(...)
```

### Creating

[](#creating)

```
use Helldar\Roles\Models\Role;
use Helldar\Roles\Models\Permission;

$role = Role::create(['slug' => 'admin']);
$permission = Permission::create(['slug' => 'update']);

$role->assignPermission($permission);

// or

$user = User::find(1);

$role = $user->createRole('Mega Admin'); // creating Role instance with "mega_admin" slug and "Mega_Admin" title.
$role = $user->createRole('Mega Admin', 'Mega Admin'); // creating Role instance with "mega_admin" slug and "Mega Admin" title.
$role = $user->createRole('Mega Admin', 'Mega Admin', true); // creating Role instance with "mega_admin" slug and "Mega Admin" title and `is_root` role.

$role->createPermission('Post edit'); // creating Permission instance with "post_edit" slug and "Post_Edit" title.
$role->createPermission('Post edit', 'Post edit'); // creating Permission instance with "post_edit" slug and "Post edit" title.
```

### Assign, revoke and sync permissions

[](#assign-revoke-and-sync-permissions)

This package allows for users to be associated with permissions and roles. Every role is associated with multiple permissions. A `Role` and a `Permission` are regular Eloquent models.

#### Assign permissions

[](#assign-permissions)

To add roles and permissions, use the following methods:

```
use \Helldar\Roles\Models\Role;
use \Helldar\Roles\Models\Permission;

// For User
$user->assignRole('role_slug');
$user->assignRole(Role::find(1));
$user->assignRole(1);

$user->assignRoles($role_1, 'role_slug_2', 3, ...);

// Adds to the user the role specified in the `default_role`
// parameter of the `config/roles.php` file.
// If `null`, then no addition will be made.
$user->assignDefaultRole();

$user->assignPermission('permission_slug');
$user->assignPermission(Permission::find(1));
$user->assignPermission(1);

$user->assignPermissions($permission_1, 'permission_2', 3, ...);

// For Role
use \Helldar\Roles\Models\Permission;

$role->assignPermission('permission_slug');
$role->assignPermission(Permission::find(1));
$role->assignPermission(1);

$role->assignPermissions($permission_1, 'permission_2', 3, ...);

// For Permission
use \Helldar\Roles\Models\Role;

$permission->assignRole('role_slug');
$permission->assignRole(Role::find(1));
$permission->assignRole(1);

$permission->assignRoles($role_1, 'role_2', 3, ...);
```

#### Revoke permissions

[](#revoke-permissions)

To revoke roles and permissions, use the following methods:

```
use \Helldar\Roles\Models\Role;
use \Helldar\Roles\Models\Permission;

// For User
$user->revokeRole('role_slug');
$user->revokeRole(Role::find(1));
$user->revokeRole(1);

$user->revokeRoles($role_1, 'role_slug_2', 3, ...);

$user->revokePermission('permission_slug');
$user->revokePermission(Permission::find(1));
$user->revokePermission(1);

$user->revokePermissions($permission_1, 'permission_2', 3, ...);

// For Role
use \Helldar\Roles\Models\Permission;

$role->revokePermission('permission_slug');
$role->revokePermission(Permission::find(1));
$role->revokePermission(1);

$role->revokePermissions($permission_1, 'permission_2', 3, ...);

// For Permission
use \Helldar\Roles\Models\Role;

$permission->revokeRole('role_slug');
$permission->revokeRole(Role::find(1));
$permission->revokeRole(1);

$permission->revokeRoles($role_1, 'role_2', 3, ...);
```

#### Syncing permissions

[](#syncing-permissions)

To synchronization roles and permissions, use the following methods:

```
// For User
$user->syncRoles([1, 2, 3, ...]);
$user->syncPermissions([1, 2, 3, ...]);

// For Role
$role->syncPermissions([1, 2, 3, ...]);

// For Permission
$permission->syncRoles([1, 2, 3, ...]);
```

### Blade

[](#blade)

If you enabled the use of directives in the [config](src/config/settings.php) file, you can still using `can()` blade directive with additional `role()` and `permission()` directives:

```
@can('permission_slug')
    I can see this text
@endcan

@if(auth()->user()->can('permission_slug'))
    I can see this text
@endif

@role('role_slug')
    I can see this text
@endrole

@role(auth()->user()->hasRole('role_slug'))
    I can see this text
@endrole

@roles('role_slug_1', 'role_slug_2', 'role_slug_3')
    I can see this text
@endroles

@roles(auth()->user()->hasRole('role_slug'))
    I can see this text
@endroles

@permission('permission_slug')
    I can see this text
@endpermission

@permission(auth()->user()->hasPermission('permission_slug'))
    I can see this text
@endpermission

@permissions('permission_slug_1', 'permission_slug_2', 'permission_slug_3')
    I can see this text
@endpermissions

@permissions(auth()->user()->hasPermission('permission_slug'))
    I can see this text
@endpermissions
```

You can only use blade directives with role/permission id or slug.

Note: use `@can()`, `@role()`, `@roles()`, `@permission()` and `@permissions()` directives is enabling separately. See [config](src/config/settings.php) file.

### Checking for permissions

[](#checking-for-permissions)

#### A `root` role:

[](#a-root-role)

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

// Checks if the user has at least one role with root access:
$user->hasRootRole(): bool
```

#### `user` » `role`:

[](#user--role)

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

// with role slug:
$user->hasRole('role_slug'): bool

// with role ID:
$user->hasRole(1): bool

// with role instance:
$user->hasRole(Role::find(1)): bool
```

#### `user` » `roles`:

[](#user--roles)

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

// with role slug:
$user->hasRoles('role_slug_1', 'role_slug_2'): bool

// with role slug as array:
$user->hasRoles(['role_slug_1', 'role_slug_2']): bool

// with role ID:
$user->hasRoles(1, 2, 3): bool

// with role instance:
$user->hasRoles(Role::find(1), Role::find(2)): bool
```

#### `user` » `permission`:

[](#user--permission)

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

// with permission slug:
$user->hasPermission('permission_slug'): bool

// with permission ID:
$user->hasPermission(1): bool

// with permission instance:
$user->hasPermission(Permission::find(1)): bool

// If the `use_can_directive` option is set to true in the settings,
// then you can also check permissions through the `can` directive:
auth()->user()->can('permission_slug'): bool
```

#### `user` » `permissions`:

[](#user--permissions)

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

// with permission slug:
$user->hasPermissions('permission_slug_1', 'permission_slug_1'): bool

// with permission slug as array:
$user->hasPermissions(['permission_slug_1', 'permission_slug_1']): bool

// with permission ID:
$user->hasPermissions(1, 2, 3): bool

// with permission ID as array:
$user->hasPermissions([1, 2, 3]): bool

// with permission instance:
$user->hasPermissions(Permission::find(1), Permission::find(2)): bool

// with permission instance as array:
$user->hasPermissions([Permission::find(1), Permission::find(2)]): bool
```

#### `role` » `permission`:

[](#role--permission)

```
$role = Role::find(1);

// with permission slug:
$role->hasPermission('permission_slug'): bool

// with permission ID:
$role->hasPermission(1): bool

// with permission instance:
$role->hasPermission(Permission::find(1)): bool

// If the `use_can_directive` option is set to true in the settings,
// then you can also check permissions through the `can` directive:
auth()->user()->can('permission_slug'): bool
```

#### `role` &gt;&gt; `permissions`:

[](#role--permissions)

```
$role = Role::find(1);

// with permission slug:
$role->hasPermissions('permission_slug_1', 'permission_slug_1'): bool

// with permission slug as array:
$role->hasPermissions(['permission_slug_1', 'permission_slug_1']): bool

// with permission ID:
$role->hasPermissions(1, 2, 3): bool

// with permission ID as array:
$role->hasPermissions([1, 2, 3]): bool

// with permission instance:
$role->hasPermissions(Permission::find(1), Permission::find(2)): bool

// with permission instance as array:
$role->hasPermissions([Permission::find(1), Permission::find(2)]): bool
```

### Artisan commands

[](#artisan-commands)

You can create/delete a role or a permission from a console with artisan commands:

```
php artisan acl:role-create {slug}
php artisan acl:role-delete {id|ID or role slug}

php artisan acl:permission-create {slug}
php artisan acl:permission-delete {id|ID or permission slug}

```

You can also invoke the creation of roles and permissions from your application:

```
Artisan::call('acl:role-create', ['slug' => $slug]);
Artisan::call('acl:role-delete', ['slug' => $slug]);

Artisan::call('acl:permission-create', ['slug' => $slug]);
Artisan::call('acl:permission-delete', ['slug' => $slug]);
```

License
-------

[](#license)

This package is released under the [MIT License](LICENSE).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity77

Established project with proven stability

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 ~13 days

Recently: every ~1 days

Total

34

Last Release

2177d ago

Major Versions

v1.10.0 → v2.0.02020-06-04

PHP version history (2 changes)v1.0.0PHP ^7.1.3

v2.3.1PHP ^7.1.3|^8.0

### Community

Maintainers

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

---

Tags

aclacl-librarylaravellaravel-rolespermissionpermission-managerpermissionsrbacrbac-managementrbac-rolesrolesroles-managementroles-permission-managementsecuritysecurity-toolslaravelsecurityaclpermissionrolespermissionsrbac

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andrey-helldar-laravel-roles/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

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

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.7k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k14.1M123](/packages/laravel-pulse)[wnikk/laravel-access-rules

Simple system of ACR (access control rules) for Laravel, with roles, groups, unlimited inheritance and possibility of multiplayer use.

103.7k1](/packages/wnikk-laravel-access-rules)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9772.3M122](/packages/roots-acorn)

PHPackages © 2026

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