PHPackages                             4msar/laravel-role-manager - 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. 4msar/laravel-role-manager

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

4msar/laravel-role-manager
==========================

Laravel Role Manager.

v1.0.1(6y ago)216MITPHPPHP &gt;=7.2

Since May 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/4msar/laravel-role-manager)[ Packagist](https://packagist.org/packages/4msar/laravel-role-manager)[ RSS](/packages/4msar-laravel-role-manager/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Laravel Role Manager
====================

[](#laravel-role-manager)

- [Installation](#installation)
- [Usage](#usage)
- [Todo](#todo)

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

[](#installation)

This package can be used in Laravel 5.4 or higher. You can install the package via composer:

```
composer require 4msar/laravel-role-manager
```

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in `config/app.php` file:

```
'providers' => [
    // ...
    MSAR\RoleManager\RoleManagerServiceProvider::class,
];
```

You can publish the migrations &amp; config file with:

```
php artisan vendor:publish --provider="MSAR\RoleManager\RoleManagerServiceProvider"
```

After the migration has been published you can create the role- and permission-tables by running the migrations:

```
php artisan migrate
```

When published, the `config/role_manager.php` config file contains:

```
return [

    /**
    * Permission List
    * Here, you can declare your needed permission, the package will be add this permission automatically
    * to the database( via middle-ware).
    * key name is the permission name and value is the details name showing for management.
    */
    "add_permission_dynamically" => false, // Make true if you want to add permission from bellow permissions array
    "permissions" => [
        // 'permission_name' => 'permission_details'
        'view_home' => 'View Admin Dashboard',
        'view_users' => 'View Admin Users',
    ],

    'unauthorized_action' => '',

    'unauthorized_action_type' =>  [
        'route' => [
            'name' => 'welcome',
            'data' => [],
        ],
        'url' => [
            'name' => '/login',
            'data' => [],
        ],
        'abort' => [
            'type' => '403',
        ],
        'dump' => [
            'data' => 'Dumping a unauthorized message.',
        ]
    ],

    "database" => [
        "role_table" => "roles",
        "permission_table" => "permissions",
        "role_permission_table" => "permission_role",
    ],
];
```

Usage
-----

[](#usage)

First, add the `MSAR\RoleManager\Traits\HasPermission;` trait to your `User` model(s):

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use MSAR\RoleManager\Traits\HasPermission;;

class User extends Authenticatable
{
    use HasPermission;

    // ...
}
```

Then, add the `\MSAR\RoleManager\Middlewares\RoleMiddleware::class` middlwware to your `Karnel.php` :

```
// .....
'has_permission' => \MSAR\RoleManager\Middlewares\RoleMiddleware::class,
```

> **NB: You have to add a column to your users table name is `role` and the users role is save to this column**

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. They require a `name` and can be created like this:

```
use MSAR\RoleManager\Models\Role;
use MSAR\RoleManager\Models\Permission;

$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit_articles', 'title' => 'Edit Articles']);
```

To create permission you can use the `config/role_manager.php` file and the `permissions` array. just make the config value `add_permission_dynamically` to `true` then add permission to the array(`permissions`).

For updating role and permission from front-end, use the code bellow

```
$role = \MSAR\RoleManager\Models\Role::where('name', 'Admin')->first();
$permissions = $request->permissions; // [1,2] | checkbox array input | permissions ids
$role->permissions()->sync($permissions);
```

For check the user has permission or not use the middleware to the route

```
Route::get('/users', 'UserController@index')->middleware('has_permission:view_users')->name('home');
```

You can use multiple permission by using the pipe(|) eg: `has_permission:view_users|update_users`

**Use Blade Directives**You can use those blade extension Has Role : Has Role

```
@hasrole(role)
@elsehasrole(another_role)
@endhasrole
```

Has Permission : User can

```
@ucan(permission)
@elseucan(another_permission)
@enducan
```

**Use Helper Functions**

```
rmHasRole($role); // pipe string | array | string
rmHasPermission($permission); // pipe string | array | string
```

Todo
----

[](#todo)

- Improve code base
- Add Command to add a role or assign permission

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Total

2

Last Release

2549d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40a496cd0ac1bbb7885d5c6e2b9b8d2d1414e532629ff2892a566c28aa88c9aa?d=identicon)[msar](/maintainers/msar)

---

Top Contributors

[![4msar](https://avatars.githubusercontent.com/u/17962782?v=4)](https://github.com/4msar "4msar (1 commits)")

---

Tags

laravelpermission-managerpermissionsrole-managementrole-manageruser-roles

### Embed Badge

![Health badge](/badges/4msar-laravel-role-manager/health.svg)

```
[![Health](https://phpackages.com/badges/4msar-laravel-role-manager/health.svg)](https://phpackages.com/packages/4msar-laravel-role-manager)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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