PHPackages                             keevitaja/keeper - 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. keevitaja/keeper

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

keevitaja/keeper
================

Keeper - Laravel authentication driver eloquent extension

1.0.1(12y ago)61802PHPPHP &gt;=5.4.0

Since Feb 23Pushed 12y agoCompare

[ Source](https://github.com/keevitaja/keeper-laravel)[ Packagist](https://packagist.org/packages/keevitaja/keeper)[ RSS](/packages/keevitaja-keeper/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Keeper for Laravel
==================

[](#keeper-for-laravel)

[![ProjectStatus](https://camo.githubusercontent.com/00dcae792ae67903ddc32494b87ff8884de68482817aebffb4ab35358274b3b2/687474703a2f2f7374696c6c6d61696e7461696e65642e636f6d2f6b6565766974616a612f6b65657065722d6c61726176656c2e706e67)](http://stillmaintained.com/keevitaja/keeper-laravel)

### role/permission based authentication package using Guard

[](#rolepermission-based-authentication-package-using-guard)

Keeper adds roles and permissions functionality to the laravels authentication driver eloquent by extending Guard class. This means, that everything you can do with Auth:: still exists.

Keeper is not a CRUD for user/role/permission database manipulation. There are just too many ways people would like to do it and we would end up with another Sentry with several wierd exceptions which need to be catched. And that's no fun...

Keeper requires atleast Laravel 4 and PHP 5.4

Install
-------

[](#install)

To install Keeper package using composer, edit composer.json file and run `composer update`.

```
"require": {
    "laravel/framework": "4.1.*",
    "keevitaja/keeper": "dev-master"
},

```

Change Auth driver in app/config/auth.php

```
'driver' => 'keeper',

```

Add service provider to app/config/app.php

```
'Keevitaja\Keeper\KeeperServiceProvider'

```

Add facade to app/config/app.php

```
'Keeper' => 'Keevitaja\Keeper\KeeperFacade'

```

Migrate tables

```
php artisan migrate --package=keevitaja/keeper

```

After that you have users, roles and permissions tables with pivot tables.

```
users:          id, email, password, created_at, updated_at
roles:          id, name, created_at, updated_at
permissions:    id, name, created_at, updated_at

```

To get a hint, how to name roles and permissions, take a look at the Usage example below.

Keeper tables are set up with pivot relations, so for example the users and roles table will have role\_user pivot relationship table. Refer to eloquent documentation under [pivot section](http://laravel.com/docs/eloquent#working-with-pivot-tables) on how to make connections between user and role.

You can add as many extra columns to the users, roles and permissions table as you need. You can create new migrations to update created tables or create your own migrations and not migrate from the package migrations. That's up to you.

Usage
-----

[](#usage)

##### `Keeper::hasRole($userId, $roleName)`

[](#keeperhasroleuserid-rolename)

Determine if user has a role - returns true/false

##### `Keeper::hasPermission($userId, $permissionName)`

[](#keeperhaspermissionuserid-permissionname)

Determine if user has a permission - returns true/false

##### `Keeper::flushCache()`

[](#keeperflushcache)

Flushes cache, please see cache section below - returns void

##### `Auth::hasRole($roleName)`

[](#authhasrolerolename)

Determine if logged user has a role - returns true/false

##### `Auth::hasPermission($permissionName)`

[](#authhaspermissionpermissionname)

Determine if logged user has a permission - returns true/false

User can have multiple roles and multiple permissions. Role can have multiple permissions as well. Permissions can be given to user directly or through a role. Keeper is very flexible and suitable for larger and smaller projects. If you need, you can ignore permissions totally and use only roles.

Roles and permission work extremly well with laravel route and filter system. It just makes sense to use them together. See the Usage example below.

Cache
-----

[](#cache)

By default cache is disabled. To activate it, run

```
php artisan config:publish keevitaja/keeper

```

Now you have copy of the config file available in the `app/config/packages/keevitaja/keeper` folder where it is safe to modify it.

- `cache` - enables or disables the cache feature (boolean)
- `cache_id` - identifier for cache key/tag names. no reason to change it (string)
- `cache_expire` - expiration time for cache in minutes (integer)
- `cache_tags` - enables or disables the usage of cache tags (boolean)

Cache Tags are not available with file or database cache driver. As `Keeper::flushCache()` requires cache tags. Flushing feature is only available with the driver which support cache tags. One of them is memcached driver.

`Keeper::flushCache()` flushes only Keeper related cache!

#### Allways clear the cache after database manipulation - users, roles and permissions with pivot tables fall into that category.

[](#allways-clear-the-cache-after-database-manipulation---users-roles-and-permissions-with-pivot-tables-fall-into-that-category)

```
Keevitaja\Keeper\Models\User::find(1)->roles()->attach(3);
Keeper::flushCache();

```

Example above adds user with ID of 1 to a role with ID of 3 and clears cache.

If you must use file driver, then you probably have to flush entire cache or come up with your own solution. Last resort would be not to use cache feature.

Managing roles and permissions
------------------------------

[](#managing-roles-and-permissions)

Keeper does not provide CRUD for database manipulation. All model methods are abstracted into traits, so it would be possible to use relations really easy in other Eloquent models in your project. See one example in Cache section.

Usage example
-------------

[](#usage-example)

```
Route::filter('finance', function()
{
	if ( ! Auth::hasRole('finance')) dd('no finance role');
});

Route::filter('invoices.create', function()
{
	if ( ! Auth::hasPermission('invoices.create')) dd('no create permission');
});

Route::filter('invoices.update', function()
{
	if ( ! Auth::hasPermission('invoices.update')) dd('no update permission');
});

Route::filter('invoices.destroy', function()
{
	if ( ! Auth::hasPermission('invoices.destroy')) dd('no destroy permission');
});

Route::group(['prefix' => 'invoices', 'before' => 'finance'], function()
{
	Route::get('show', 'InvoicesController@show');
	Route::get('create', 'InvoicesController@create')->before('invoices.create');
	Route::get('destroy', 'InvoicesController@destroy')->before('invoices.destroy');
});

Route::get('invoices/update', 'InvoicesController@update')->before('invoices.update');
```

Filter names in this example are the role and permission names. You can name permissions any way you like, but `controller.permission` seems to make sense. At least for me.

For this example to work you need a role

- finance

and permissions

- invoices.create
- invoices.update
- invoices.destroy

These routes and filters give you the following setup:

- `invoices/show` can be accessed by all users who have `finance` role
- `invoices/create` can be accessed by all users who have `finance` role and `invoices.create` permission
- `invoices/destroy` can be accessed by all users who have `finance` role and `invoices.destroy` permission
- `invoices/update` can be accessed by all users who have `invoices.update` permission

It does not matter, if permission is given to user directly (permission\_user pivot) or through a role (permission\_role pivot).

If you like this
----------------

[](#if-you-like-this)

please follow me [@keevitaja](https://twitter.com/keevitaja)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

2

Last Release

4462d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/095d59168b7cb0cf90ecb948c3e7de7a58e1528e7a19759a628ea15db65f3b72?d=identicon)[keevitaja](/maintainers/keevitaja)

---

Top Contributors

[![keevitaja](https://avatars.githubusercontent.com/u/158787?v=4)](https://github.com/keevitaja "keevitaja (32 commits)")

---

Tags

laravelAuthenticationrolespermissionsguard

### Embed Badge

![Health badge](/badges/keevitaja-keeper/health.svg)

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

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[pktharindu/nova-permissions

Laravel Nova Grouped Permissions (ACL)

136387.1k](/packages/pktharindu-nova-permissions)[hasinhayder/tyro

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

6712.1k2](/packages/hasinhayder-tyro)[silvanite/novatoolpermissions

Laravel Nova Permissions (Roles and Permission based Access Control (ACL))

100256.7k2](/packages/silvanite-novatoolpermissions)[beatswitch/lock-laravel

A Laravel Driver for Lock.

15529.1k1](/packages/beatswitch-lock-laravel)[sametsahindogan/laravel-jwtredis

This package allows JWT-authenticated users to be stored and management in Redis with their roles, permissions, statuses and anything you want.

1221.9k](/packages/sametsahindogan-laravel-jwtredis)

PHPackages © 2026

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