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

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

ricardoboss/laravel-roles-migrations
====================================

Write migrations for your laravel roles.

v1.2.1(5y ago)31271MITPHPPHP ^7.2CI failing

Since Dec 4Pushed 5y agoCompare

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

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

laravel-roles-migrations
========================

[](#laravel-roles-migrations)

Adds migrations for [`jeremykenedy/laravel-roles`](https://github.com/jeremykenedy/laravel-roles).

Overview
--------

[](#overview)

This package aims to provide migration functionality for roles and permissions (and their relationships).

1. [Installation](#installation)
2. [Usage](#usage)
    1. [Creating Migrations](#creating-migrations)
    2. [Writing Migrations](#writing-migrations)
    3. [Examples](#examples)

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

[](#installation)

Simply require this package with composer:

```
composer require ricardoboss/laravel-roles-migrations
```

Usage
-----

[](#usage)

### Creating Migrations

[](#creating-migrations)

This package adds a new abstract class - `RolesMigration` - which you can use to write migrations for your roles.

To add a new migration, simply execute

```
php artisan make:rolesmigration MyNewRolesMigration
```

to add a new migration (which can be found in `database/migrations/xxx_xx_xx_xxxxxx_my_new_roles_migration.php`).

Open the migration. Notice how the class `extends` the new `RolesMigration` class instead of the default `Migration` class from Laravel.

Now comes the interesting part, writing the migrations.

### Writing Migrations

[](#writing-migrations)

A roles migration consists of four protected arrays which define what the migration does:

- `$permissions`: contains permission definitions which shall be added
- `$roles`: contains role definitions which shall be added
- `$toAttach`: defines which permissions shall be attached to what role
- `$toDetach`: defines which permissions shall be detached from what role

An example of each migration type and their outcome can be found here:

### Examples

[](#examples)

#### Permissions

[](#permissions)

```
$permissions = [
    [
        'name' => "List users",
        'slug' => "users.list", // optional
        'description' => "Permission to list all users."
    ]
];
```

The `slug` value is optional. It will be derived from the name if missing.

When the migration is executed, the above configuration will add a new permission to your database. This exact permission will be removed in case of a rollback.

#### Roles

[](#roles)

```
$roles = [
    [
        'name' => "Admin",
        'level' => 10,
        'slug' => "admin", // optional
        'description' => "A user with all available permissions." // optional
    ]
];
```

The `slug` and `description` values are optional. If `slug` is missing, it will be derived from the name. The default value for `description` is `null`.

#### ToAttach &amp; ToDetach

[](#toattach--todetach)

```
$toAttach = [
    'admin' => [
        'users.list',
        // more permissions...
    ]
];
```

`$toAttach` and `$toDetach` have the same structure. They consist of nested arrays which declare what role gets or looses which permissions.

The key of the array must be the `slug` of a role whereas the value must be an array of permission `slug`s. You can list as many permissions as you want for each role.

> The order in which permissions are attached and detached matters: if you have the same configuration in both `$toAttach` and `$toDetach`, the outcome will be that nothing changed since the permissions are first attached and *then* detached.

Contributing
------------

[](#contributing)

Feel free to fork the repository and create a pull request. You are encouraged to adhere to the [PSR-12](https://www.php-fig.org/psr/psr-12/)coding style guide.

### To-Do List

[](#to-do-list)

- Basic migrations and rollbacks
- `artisan` commands
- support for updating existing roles/permissions
- write tests

If you see a missing feature you want or find a bug, please create an issue and describe it.

License
-------

[](#license)

The source code of this package is free software and distributed under the terms of the [MIT License](https://github.com/ricardoboss/laravel-roles-migrations/blob/master/LICENSE).

---

Thanks to [jeremykenedy](https://github.com/jeremykenedy) for creating the [`laravel-roles`](https://github.com/jeremykenedy/laravel-roles) package and of course [taylorotwell](https://github.com/taylorotwell) for creating such an amazing framework.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~57 days

Total

4

Last Release

2180d ago

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

v1.2.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ea436f1f084470f9d75ca0fde95e2418ba03d560bc4e20e03171648c123fa80?d=identicon)[ricardoboss](/maintainers/ricardoboss)

---

Top Contributors

[![ricardoboss](https://avatars.githubusercontent.com/u/6266356?v=4)](https://github.com/ricardoboss "ricardoboss (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelmigrationsrolespermissions

### Embed Badge

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

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

###  Alternatives

[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)[jeremykenedy/laravel-roles

A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3 up to 12.

1.0k826.8k7](/packages/jeremykenedy-laravel-roles)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)[smarch/watchtower

Front-end for the Shinboi Auth system of Users / Roles / Permissions in Laravel 5

523.0k](/packages/smarch-watchtower)

PHPackages © 2026

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