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

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

alleyinteractive/simple-laravel-roles
=====================================

Simple PHP-based permissions in Laravel

0.1.2(5y ago)2621MITPHP

Since Mar 4Pushed 5y ago3 watchersCompare

[ Source](https://github.com/alleyinteractive/simple-laravel-roles)[ Packagist](https://packagist.org/packages/alleyinteractive/simple-laravel-roles)[ Docs](https://github.com/alleyinteractive/simple-laravel-roles)[ RSS](/packages/alleyinteractive-simple-laravel-roles/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Simple Laravel Roles
====================

[](#simple-laravel-roles)

This package adds very simple role/capability functionality to a Laravel application, where the roles and capabilities are defined using a config file.

Once roles and capabilities are defined and a role is assigned to a user, capabilities can be checked using Laravel's built-in authorization functionality:

```
if ($user->can('edit_posts')) {
    // Cool.
}
```

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

[](#installation)

Via Composer

```
$ composer require alleyinteractive/simple-laravel-roles
```

Setup and Configuration
-----------------------

[](#setup-and-configuration)

1. Once the package is installed, you can publish the package files using artisan:

    ```
    php artisan vendor:publish --provider="Alley\SimpleRoles\SimpleRolesServiceProvider"
    ```

    This will add two files to your application:

    - `config/roles.php` is where you'll define your roles.
    - `database/migrations/_add_roles_to_users_table.php` adds a `roles` column to the `users` table. Delete this file if it doesn't apply to your use case.
2. Configure your roles and capabilities in `config/roles.php`.
3. Run `php artisan migrate` if you just need to add `roles` to the `users` table. If you want to add `roles` to more tables, create your migrations first.
4. Add the `Alley\SimpleRoles\HasRoles` trait to the `User` model and/or any models that will have roles.

Usage
-----

[](#usage)

### In Gates and Policies

[](#in-gates-and-policies)

This package is intended to augment Laravel's built-in authorization functionality by adding role and capability buckets in which to add users or other models. These buckets can be checked during your Gate or Policy checks.

Here's an example Policy method that leverages capabilities to allow deleting a post if the user owns the post or the user is allowed to delete others' posts:

```
use App\Models\Post;
use App\Models\User;
use Illuminate\Auth\Access\Response;

/**
 * Determine if the given post can be deleted by the user.
 *
 * @param  \App\Models\User  $user
 * @param  \App\Models\Post  $post
 * @return \Illuminate\Auth\Access\Response
 */
public function delete(User $user, Post $post)
{
    return $user->id === $post->user_id || $user->can('delete_others_posts')
        ? Response::allow()
        : Response::deny('You do not own this post.');
}
```

### In place of Gates and Policies

[](#in-place-of-gates-and-policies)

Depending on the complexity of your application, this package could even replace your gate and policy checks. It will [intercept all Gate checks before other authorization checks](https://laravel.com/docs/8.x/authorization#intercepting-gate-checks)and if the user has the given ability as a capability in any of their roles, the check will pass. With this, Laravel's core authorization functionality will work as usual, and capabilities will be checked instead of defined gates or policies. In other words, if a user has a role with the `delete_posts` capability, that capability can be checked using:

```
if ($user->can('delete_posts')) { /* ... */ }
```

As well as in blade templates:

```
@can('delete_posts')
  // ...
@endcan
```

The `HasRoles` trait also includes some helpers to check capabilities and roles:

- `hasCapability(string $capability): bool`: Check if the object has the given capability.
- `hasRole(string $role): bool`: Check if the object has the given role.
- `getRoles(): Collection`: Get the roles for the object as Role objects.
- `setRoles(array $roles): bool`: Set the object's roles.
- `addRole(string $role): bool`: Append a role to the object.
- `removeRole(string $role): bool`: Remove a role from the object.

Further, the package provides a `Role` class which can be used to check capabilities on a specific role.

```
$contributor = new Role('contributor');
if ($contributor->can('create_posts')) { /* ... */ }
```

Change log
----------

[](#change-log)

See the [changelog](changelog.md).

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email the author email (found in `composer.json`) instead of using the issue tracker.

Credits
-------

[](#credits)

- \[Matthew Boynes\]\[@mboynes\]

License
-------

[](#license)

MIT. Please see the [license file](license.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

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

3

Last Release

1896d ago

### Community

Maintainers

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

---

Top Contributors

[![mboynes](https://avatars.githubusercontent.com/u/465154?v=4)](https://github.com/mboynes "mboynes (10 commits)")

---

Tags

laravelrolespermissions

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[shanmuga/laravel-entrust

This package provides a flexible solution to add ACL to Laravel

68312.9k2](/packages/shanmuga-laravel-entrust)[hasinhayder/tyro

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

6712.1k2](/packages/hasinhayder-tyro)[beatswitch/lock-laravel

A Laravel Driver for Lock.

15529.1k1](/packages/beatswitch-lock-laravel)[pingpong/trusty

Roles and Permissions for Laravel 4

2680.0k9](/packages/pingpong-trusty)[phpzen/laravel-rbac

Role based access control for Laravel 5

383.2k](/packages/phpzen-laravel-rbac)

PHPackages © 2026

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