PHPackages                             kettasoft/gatekeeper - 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. kettasoft/gatekeeper

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

kettasoft/gatekeeper
====================

A lightweight and powerful package for handling permissions and provisions in Laravel

1.4.5(2y ago)2131MITPHPPHP ^8.0

Since Aug 7Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (11)Used By (0)

Gatekeeper
==========

[](#gatekeeper)

This package provides a comprehensive system for managing roles and permissions in Laravel applications. It allows for easy creation and management of roles, assigning permissions to specific roles, and controlling access to different parts of the application based on a user's assigned roles and permissions.

[![Total Downloads](https://camo.githubusercontent.com/d8311d99d178e382f4466e94078fd7fb87d3c4a582ca8d95cda79ed9194431a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b65747461736f66742f676174656b65657065723f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/kettasoft/gatekeeper)[![Latest Stable Version](https://camo.githubusercontent.com/01d4ff94eb7d2ff5c86beab8398ce1651ffef6bf5aece8b1b4659a338c59aa59/687474703a2f2f706f7365722e707567782e6f72672f6b65747461736f66742f676174656b65657065722f763f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/kettasoft/gatekeeper)[![License](https://camo.githubusercontent.com/03829934cf6a0f2c395741908bf9fc7ccb650a6994e5e5080f2d177d6e837155/687474703a2f2f706f7365722e707567782e6f72672f6b65747461736f66742f676174656b65657065722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/kettasoft/gatekeeper)[![PHP Version Require](https://camo.githubusercontent.com/8dc3c700eaa3c9ad9a17bc715dec953727a308025c497a70e20cf55b6a64443f/687474703a2f2f706f7365722e707567782e6f72672f6b65747461736f66742f676174656b65657065722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/kettasoft/gatekeeper)

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

[](#installation)

### You can install the package using composer:

[](#you-can-install-the-package-using-composer)

```
composer require kettasoft/gatekeeper
```

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework, you must install the service provider:

```
// config/app.php
'providers' => [
    ...
    Kettasoft\Gatekeeper\Providers\GatekeeperServiceProvider::class,
];
```

### publish the config/gatekeeper.php config

[](#publish-the-configgatekeeperphp-config)

```
php artisan vendor:publish --provider="Kettasoft\Gatekeeper\Providers\GatekeeperServiceProvider" --tag="config"
```

### WARNING

[](#warning)

If this command did not publish any files, chances are, the Laratrust service provider hasn't been registered. Try clearing your configuration cache

```
php artisan config:clear
```

### Run the setup command:

[](#run-the-setup-command)

IMPORTANT: Before running the command go to your config/gatekeeper.php file and change the values according to your needs.

```
php artisan gatekeeper:migrate
```

### This command will generate the migrations, create the Role and Permission models

[](#this-command-will-generate-the-migrations-create-the-role-and-permission-models)

```
use Kettasoft\Gatekeeper\Contracts\GatekeeperInterface;
use Kettasoft\Gatekeeper\Traits\Gatekeeper;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements GatekeeperInterface
{
    use Gatekeeper;

    // ...
}
```

### Dump the autoloader:

[](#dump-the-autoloader)

```
composer dump-autoload
```

### Run the migrations:

[](#run-the-migrations)

```
php artisan migrate
```

Roles &amp; Permissions
-----------------------

[](#roles--permissions)

### Setting things up

[](#setting-things-up)

Let's start by creating the following Roles:

```
$owner = Role::create([
    'name' => 'owner',
    'display_name' => 'Project Owner', // optional
    'description' => 'User is the owner of a given project', // optional
]);

$admin = Role::create([
    'name' => 'admin',
    'display_name' => 'User Administrator', // optional
    'description' => 'User is allowed to manage and edit other users', // optional
]);
```

Role Assignment &amp; Removal:

```
$user->addRole($admin); // parameter can be a Role object, array, id or the role string name
// equivalent to $user->roles()->attach([$admin->id]);

$user->addRoles([$admin, $owner]); // parameter can be a Role object, array, id or the role string name
// equivalent to $user->roles()->attach([$admin->id, $owner->id]);

$user->syncRoles([$admin->id, $owner->id]);
// equivalent to $user->roles()->sync([$admin->id, $owner->id]);

$user->syncRolesWithoutDetaching([$admin->id, $owner->id]);
// equivalent to $user->roles()->syncWithoutDetaching([$admin->id, $owner->id]);
```

### Removal

[](#removal)

```
$user->removeRole($admin); // parameter can be a Role object, array, id or the role string name
// equivalent to $user->roles()->detach([$admin->id]);

$user->removeRoles([$admin, $owner]); // parameter can be a Role object, array, id or the role string name
// equivalent to $user->roles()->detach([$admin->id, $owner->id]);
```

### User Permissions Assignment &amp; Removal

[](#user-permissions-assignment--removal)

You can give single permissions to a user, so in order to do it you only have to make:

Assignment
----------

[](#assignment)

```
$user->givePermission(['admin-create', 'admin-delete']); // parameter can be a Permission object, array, id or the permission string name

$user->syncPermissions([$editUser->id, $createPost->id]);
// equivalent to $user->permissions()->sync([$editUser->id, createPost->id]);

$user->syncPermissionsWithoutDetaching([$editUser, $createPost]); // parameter can be a Permission object, array or id
    // equivalent to $user->permissions()->syncWithoutDetaching([$createPost->id, $editUser->id]);
```

Middleware
==========

[](#middleware)

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

[](#configuration)

The middleware are registered automatically as role, permission. If you want to change or customize them, go to your config/gatekeeper.php and set the middleware.register value to false and add the following to the routeMiddleware array in app/Http/Kernel.php:

```
'role' => \Kettasoft\Gatekeeper\Middleware\Role::class,
'permission' => \Kettasoft\Gatekeeper\Middleware\Permission::class,
```

Concepts
--------

[](#concepts)

You can use a middleware to filter routes and route groups by permission, role:

```
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
    Route::get('/', 'AdminController@welcome');
    Route::get('/manage', ['middleware' => ['permission:manage-admins'], 'uses' => 'AdminController@manageAdmins']);
});
```

If you use the pipe symbol it will be an OR operation:

```
'middleware' => ['role:admin|root']
// $user->hasRole(['admin', 'root']);

'middleware' => ['permission:edit-post|edit-user']
// $user->hasRole(['edit-post', 'edit-user']);
```

To emulate AND functionality you can do:

```
'middleware' => ['role:owner|writer,require_all']
// $user->hasRole(['owner', 'writer'], true);

'middleware' => ['permission:edit-post|edit-user,require_all']
// $user->isAbleTo(['edit-post', 'edit-user'], true);
```

### Using Different Guards

[](#using-different-guards)

If you want to use a different guard for the user check you can specify it as an option:

```
'middleware' => ['role:owner|writer,require_all|guard:api']
'middleware' => ['permission:edit-post|edit-user,guard:some_new_guard']
```

Middleware Return
-----------------

[](#middleware-return)

The middleware supports two types of returns in case the check fails. You can configure the return type and the value in the config/gatekeeper.php file.

Abort
-----

[](#abort)

By default the middleware aborts with a code 403 but you can customize it by changing the gatekeeper.middleware.handlers.abort.code value.

Redirect
--------

[](#redirect)

To make a redirection in case the middleware check fails, you will need to change the middleware.handling value to redirect and the gatekeeper.middleware.handlers.redirect.url to the route you need to be redirected. Leaving the configuration like this:

```
'handling' => 'redirect',
'handlers' => [
    'abort' => [
        'code' => 403
    ],
    'redirect' => [
        'url' => '/home',       // Change this to the route you need
        'message' => [          // Key value message to be flashed into the session.
            'key' => 'error',
            'content' => ''     // If the content is empty nothing will be flashed to the session.
        ]
    ]
]
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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 ~4 days

Total

10

Last Release

976d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/514a1d3f5416af98e8f0174f21cd94d357204a98704e92fd37db2903b08e2057?d=identicon)[kettasoft](/maintainers/kettasoft)

---

Top Contributors

[![kettasoft](https://avatars.githubusercontent.com/u/80687771?v=4)](https://github.com/kettasoft "kettasoft (82 commits)")

---

Tags

application-securityauthorizationcheckerchecksgategatekeeperkeeperlaravelpermissionsphprbacrolessecurity

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/kettasoft-gatekeeper/health.svg)

```
[![Health](https://phpackages.com/badges/kettasoft-gatekeeper/health.svg)](https://phpackages.com/packages/kettasoft-gatekeeper)
```

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