PHPackages                             rs/laravel-doorman - 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. rs/laravel-doorman

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

rs/laravel-doorman
==================

Will the doorman let you in? Only if you've got the right set of permissions.

v2.1(2y ago)04.4k↓66.7%2[1 issues](https://github.com/RedSnapper/laravel-doorman/issues)mitPHPPHP ^8.0CI failing

Since Nov 6Pushed 2y ago2 watchersCompare

[ Source](https://github.com/RedSnapper/laravel-doorman)[ Packagist](https://packagist.org/packages/rs/laravel-doorman)[ RSS](/packages/rs-laravel-doorman/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (8)Used By (0)

Laravel Version Control
=======================

[](#laravel-version-control)

This package provides traits to use to quickly scaffold role based permissions to your laravel project.

Once installed we can do the following:

```
// Give a permission to a role
$role->givePermissionTo('view users');

// Assign a user to a role
$user->assignRole($role);

// Check if a user has permission to
$user->can('view users');
```

Permissions are registered with Laravel's gate and so it is possible to check using any laravel gate methods.

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

[](#installation)

```
composer require rs/laravel-doorman

```

The service provider will be automatically registered.

Configuration file can be published using the artisan command.

```
php artisan vendor:publish --tag="doorman-config"
```

Configuration
-------------

[](#configuration)

Configuration allows you to specify which models you would like to use for the Role and Permission. By default they use models defined by the package. If extra functionality is required or you would like to use your own models then they can be updated here.

Migrations
----------

[](#migrations)

```
php artisan migrate

```

This will run the default migrations needed. If you like to change the default migrations you can publish the migration files.

```
php artisan vendor:publish --tag="doorman-migrations"
```

If you dont want any migrations to run then you can disable the migrations in the config file.

Basic usage
-----------

[](#basic-usage)

### User

[](#user)

Add the `HasPermissionsViaRoles` trait to your `User` model.

```
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Redsnapper\LaravelDoorman\Models\Traits\HasPermissionsViaRoles;

    class User extends Authenticatable
    {
        use HasPermissionsViaRoles;

        // ...
    }
```

A role can be assigned to any user:

```
$user->assignRole('writer');

// You can also assign multiple roles at once
$user->assignRole('editor', 'admin');
// or as an array
$user->assignRole(['editor', 'admin']);
```

A role can be removed from a user:

```
$user->removeRole('editor');
```

Roles can also be synced:

```
// All current roles will be removed from the user and replaced by the array given
$user->syncRoles(['editor', 'admin']);
```

You can determine if a user has a certain role:

```
$user->hasRole($role);
```

Permissions and roles can be accessed from the user using the `HasPermissionsViaRoles` trait.

```
// permissions relaitionship
$permissions = $user->permissions;
// roles relationship
$roles = $user->roles
```

You can check if a user has a permission:

```
$user->hasPermissionTo('edit users'); // Name of permission
$user->hasPermissionTo($somePermission->id); // Id of permission
$user->hasPermissionTo($somePermission); // Permission Model
```

### Permissions and roles

[](#permissions-and-roles)

A permission can be assigned to a role using 1 of these methods:

```
$role->givePermissionTo($permission);
$permission->assignRole($role);
```

Multiple permissions can be synced to a role using 1 of these methods:

```
$role->syncPermissions($permissions);
$permission->syncRoles($roles);
```

A permission can be removed from a role using 1 of these methods:

```
$role->revokePermissionTo($permission);
$permission->removeRole($role);
```

Permission and role customization
---------------------------------

[](#permission-and-role-customization)

If you would like to setup your own permission and role models then you can update the configuration to use your own models.

The existing doorman models can be extended or the models can use the existing traits.

When implementing your own models the models must fulfil the `Role` and `Permission` Contracts.

An example of a role model.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Redsnapper\LaravelDoorman\Models\Contracts\Role as RoleContract;
use Redsnapper\LaravelDoorman\Models\Traits\HasPermissions;

class Role extends Model implements RoleContract
{
    use HasPermissions;

}
```

An example of the permission model.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Redsnapper\LaravelDoorman\Models\Contracts\Permission as PermissionContract;
use Redsnapper\LaravelDoorman\Models\Traits\HasRoles;
use Redsnapper\LaravelDoorman\Models\Traits\PermissionIsFindable;

class Permission extends Model implements PermissionContract
{
    use HasRoles, PermissionIsFindable;

}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% 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 ~306 days

Recently: every ~329 days

Total

6

Last Release

754d ago

Major Versions

v1.0.1 → v2.0.02020-09-07

PHP version history (3 changes)1.0.0PHP ^7.3.0

v2.0.2PHP ^7.3.0|^8.0

v2.1PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1785064?v=4)[Mr Ben Griffin](/maintainers/MrBenGriffin)[@MrBenGriffin](https://github.com/MrBenGriffin)

![](https://avatars.githubusercontent.com/u/6851104?v=4)[rstechnical](/maintainers/rstechnical)[@rstechnical](https://github.com/rstechnical)

---

Top Contributors

[![paramdhal](https://avatars.githubusercontent.com/u/1278858?v=4)](https://github.com/paramdhal "paramdhal (20 commits)")[![mmltonge](https://avatars.githubusercontent.com/u/45395163?v=4)](https://github.com/mmltonge "mmltonge (10 commits)")[![cammackmatthew](https://avatars.githubusercontent.com/u/10643740?v=4)](https://github.com/cammackmatthew "cammackmatthew (4 commits)")[![pazitron1](https://avatars.githubusercontent.com/u/24591690?v=4)](https://github.com/pazitron1 "pazitron1 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rs-laravel-doorman/health.svg)

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

###  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)[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)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)

PHPackages © 2026

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