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

ActiveLibrary

dcastanera/laravel-roles
========================

Roles and Permissions for Laravel 5

09PHP

Since Feb 28Pushed 8y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Roles &amp; Permissions
===============================

[](#laravel-roles--permissions)

This package is designed to provide a very basic roles and permissions structure for Laravel 5.

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

[](#installation)

To install this roles package, you must use Composer. Type the following in your Command Line Interface

```
composer require dcastanera/laravel-roles

```

This should install all the roles files to your vendors directory.

### Service Provider

[](#service-provider)

Next we want to register the service provider in the /config/app.php file. Go to the array for providers and enter the following:

```
DCastanera\Roles\RolesServiceProvider::class,

```

### Database Migrations

[](#database-migrations)

Now we want to bring in the migrations by typing the following:

```
php artisan vendor:publish

```

The above command copied a new migration into your migrations folder so now we need to run a migration.

```
php artisan migrate

```

### User Model

[](#user-model)

In order for the roles to attach to the user, we need to add the Roleable trait in the user model. Add the following to the top of the user model to include the trait.

```
use DCastanera\Roles\Roleable;

```

Then add the following inside the class after `use notifiable`.

```
use Roleable;

```

You should be all set after that.

Roles
-----

[](#roles)

To use Roles you need to make sure you reference the Roles model.

```
use DCastanera\Roles\Role;

```

### Creating Roles

[](#creating-roles)

To create a role you can try the following:

```
$role = new Role;
$role->name = 'Super Administrator';
$role->slug = 'super';
$role->description = 'This is the Super Administrator role.';
$role->save();

```

or you can also use the create method:

```
$role = Role::create([
    'name' => 'Administrator',
    'slug' => 'admin',
    'description' => 'This is the system Administrator.',
]);

```

both should function the same.

### Attaching Roles

[](#attaching-roles)

To attach a role to a user, we simply need to call both objects and save them using the eloquent roles method as follows:

```
// First grab the user object
$user = User::find(1);

// Next grab the role object
$role = Role::find(1);

// Use the following to attach them.
$user->roles()->save($role);

```

### Detaching Roles

[](#detaching-roles)

To detach a role from a user, we simply need to call both objects and delete the role from the roles method as follows:

```
// First grab the user object
$user = User::find(1);

// Next grab the role object
$role = Role::find(1);

// Use the following to detach them.
$user->roles()->delete($role);

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% 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/de434862bb68cf816691678373b6302297616d9f6437bfcaa025f5a0d85cb69e?d=identicon)[dcastanera](/maintainers/dcastanera)

---

Top Contributors

[![DevTechOps](https://avatars.githubusercontent.com/u/27882491?v=4)](https://github.com/DevTechOps "DevTechOps (9 commits)")[![dcastanera](https://avatars.githubusercontent.com/u/13420672?v=4)](https://github.com/dcastanera "dcastanera (6 commits)")

### Embed Badge

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

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

PHPackages © 2026

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