PHPackages                             oncampus/laravel-role-perms - 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. oncampus/laravel-role-perms

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

oncampus/laravel-role-perms
===========================

Role based permissions for laravel

020PHP

Since Jul 8Pushed 6y agoCompare

[ Source](https://github.com/oncampus/laravel-role-perms)[ Packagist](https://packagist.org/packages/oncampus/laravel-role-perms)[ RSS](/packages/oncampus-laravel-role-perms/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

Install
=======

[](#install)

```
composer require oncampus/laravel-role-perms

```

Extend the user class
---------------------

[](#extend-the-user-class)

Import the Roles trait in the User.php file:

```
use Oncampus\LaravelRolePerms\Traits\Roles;

```

Inside the user class use the trait:

```
use Roles;

```

Migration
---------

[](#migration)

```
php artisan migrate

```

Seeds
-----

[](#seeds)

```
php artisan db:seed --class="Oncampus\LaravelRolePerms\Database\Seeds"

```

By default the following seeder creates the admin role and some permission. If there is a user with the name admin, then by default he gets the role admin.

Usage
=====

[](#usage)

Functions
---------

[](#functions)

### User Model

[](#user-model)

To check if a user model has a permission or a role you can use this:

```
$user->hasPermission('permissionName', [Object $entity]); // true || false
$user->hasRole('roleName', [Object $entity]); // true || false

```

The user function results will be cached! Use `RolePerms::clearPermissionCache([User $user]);` or `RolePerms::clearRoleCache([User $user]);` to clean up if needed.

### Facade

[](#facade)

Include the Facade to use the following functions.

```
use Oncampus\LaravelRolePerms\Facades\RolePerms;

```

Now you can use the following functions:

```
RolePerms::userHasRole(User  $user, String  $roleName, [Object $entity]); // true || false

RolePerms::userHasPermission(User  $user, String  $permissionName, [Object $entity]); // true || false

RolePerms::roleHasPermission(String  $roleName, String  $permissionName); // true || false

RolePerms::grantRole(User  $user, String  $roleName, [Object $entity]); // true || false

RolePerms::grantPermission(String  $roleName, String  $permissionName); // true || false

RolePerms::revokeRole(User  $user, String  $roleName, [Object $entity]); // true || false

RolePerms::revokePermission(String  $roleName, String  $permissionName); // true || false

RolePerms::clearRoleCache([User $user]); // true || false

RolePerms::clearPermissionCache([User $user]); // true || false

RolePerms::createRole(String  $roleName); // Role || false

RolePerms::createPermission(String  $permissionName); // Permission || false

RolePerms::deleteRole(String  $roleName); // true || false

RolePerms::deletePermission(String  $permissionName); // true || false

```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2eb47b3cdf8e8ae1d3f0ee3a2a77fb0d87a01c932c359f794db4814d725c9ce6?d=identicon)[oncampus](/maintainers/oncampus)

---

Top Contributors

[![bedoke](https://avatars.githubusercontent.com/u/14050253?v=4)](https://github.com/bedoke "bedoke (60 commits)")

### Embed Badge

![Health badge](/badges/oncampus-laravel-role-perms/health.svg)

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

###  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)
