PHPackages                             anlutro/access - 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. anlutro/access

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

anlutro/access
==============

RBAC models for Laravel 4.

0.1.8(11y ago)1449PHPPHP &gt;=5.4.0

Since Oct 19Pushed 11y ago1 watchersCompare

[ Source](https://github.com/anlutro/access)[ Packagist](https://packagist.org/packages/anlutro/access)[ RSS](/packages/anlutro-access/feed)WikiDiscussions master Synced yesterday

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

Access - RBAC for Laravel 4 [![Build Status](https://camo.githubusercontent.com/0bcba24a973a16569afb604a59b11d8f06c730bf6eb1544382a972c36984715a/68747470733a2f2f7472617669732d63692e6f72672f616e6c7574726f2f6163636573732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/anlutro/access)
=====================================================================================================================================================================================================================================================================================================

[](#access---rbac-for-laravel-4-)

My stab at an RBAC system for Laravel 4.

This is probably extremely query intensive and I have not made many attempts to optimize the number of queries ran/in-memory caching being done.

I wrote this with the intention of using it on small systems with a low number of concurrent users. It is made for systems where you need to control permissions on row-basis rather than just some generalized roles and permissions.

Contribution
------------

[](#contribution)

Bug reports, feature suggestions and code improvements are highly welcome. If you make a pull request, do make sure that your changes pass the unit tests.

Use the github issue system! If you just want to have a chat, look for me in #laravel on freenode.

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

[](#installation)

### Requirements

[](#requirements)

- PHP 5.4 or higher
- Laravel 4.1 or higher

### Install

[](#install)

`composer require anlutro/access`

Check packagist.org or the github tag list for the latest stable release, or use dev-master if you like living on the edge.

### Copy migrations

[](#copy-migrations)

Copy migrations from `vendor/anlutro/access/src/migrations` to your app's migration directory. Alternatively, run them with `php artisan migrate --package anlutro/access` if you just want to play around with the system - copying the migration files manually is recommended for production setups.

### Create your user model

[](#create-your-user-model)

Because you probably want to put your own functions and fields on the User model/table, you create the user model yourself. There are two ways to do this and ensure it works with the RBAC system - inheritance (extending a base class) or traits.

```
class MyUser extends anlutro\Access\Models\User {}

class MyUser extends Eloquent implements anlutro\Access\Interfaces\SubjectInterface
{
	use anlutro\Access\Traits\UserSubject;
}
```

You are responsible for creating the user table. Remember to update your `app/config/auth.php` file to reflect your model.

### Create one or more resource models

[](#create-one-or-more-resource-models)

Again you can do this with inheritance or traits:

```
class MyResource extends anlutro\Access\Models\Resource {}

class MyResource extends Eloquent implements anlutro\Access\Interfaces\ResourceInterface
{
	use anlutro\Access\Traits\ResourceSubject;
}
```

You are responsible for creating any resource tables.

Usage
-----

[](#usage)

First, we need to create some permissions.

```
use anlutro\Access\Models\Permission;
$lowPermission = Permission::create(['name' => 'Normal Permission']);
$highPermission = Permission::create(['name' => 'High Level Permission']);
```

Then, let's assign some permissions to actions on one of our resource models. Resource actions with no permissions assigned to them are allowed by default, so be careful.

```
MyResource::addGlobalPermissionTo('show', $lowPermission);
MyResource::addGlobalPermissionTo('create', $lowPermission);
MyResource::addGlobalPermissionTo('create', $highPermission);
// MyResource::removeGlobalPermissionTo('create', $highPermission);
```

You can also assign permissions required on specific resources.

```
$resource = MyResource::first();
$res->addPermissionTo('create', $superHighPermission);
// $res->removePermissionTo('create', $superHighPermission);
```

Let's create a couple of roles. This step is optional, permissions can be added to users directly if you like - the syntax is exactly the same.

```
use anlutro\Access\Models\Role;
$userRole = Role::create(['name' => 'User Role']);
$adminRole = Role::create(['name' => 'Admin Role']);
$bannedRole = Role::create(['name' => 'Banned']);
$userRole->addPermission($lowPermission);
$adminRole->addPermission($lowPermission);
$adminRole->addPermission($highPermission);
$bannedRole->denyPermission($lowPermission);
```

Let's assign the user role to one of our users.

```
$user = User::first();
$user->addRole($userRole);
// $user->removeRole($userRole);
```

Now, the user should have access to show, but not create a MyResource.

```
$resource = MyResource::first();
var_dump( $user->hasPermissionTo('show', $resource) );
$resource = new MyResource;
var_dump( $user->hasPermissionTo('create', $resource) );
```

If we assign the user the admin role, however, he should have access to create as well.

```
$user->addRole($adminRole);
var_dump( $user->hasPermissionTo('create', $resource) );
```

Most of the time you'll be running these checks against the currently logged in user. The Access facade has some handy shorthand functions for this.

```
use anlutro\Access\Access;
var_dump( Access::allowed('show', $resource) );
var_dump( Access::denied('create', $resource) );
```

License
-------

[](#license)

The contents of this repository is released under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Recently: every ~82 days

Total

9

Last Release

4310d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48f62855097c02888b96494da9a389988cd7ecb9001465f8ec30f15672fb5b5a?d=identicon)[anlutro](/maintainers/anlutro)

---

Top Contributors

[![anlutro](https://avatars.githubusercontent.com/u/163093?v=4)](https://github.com/anlutro "anlutro (27 commits)")

### Embed Badge

![Health badge](/badges/anlutro-access/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M169](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M23](/packages/yajra-laravel-oci8)[illuminate/queue

The Illuminate Queue package.

21332.6M1.5k](/packages/illuminate-queue)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[hasinhayder/tyro

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

6783.6k5](/packages/hasinhayder-tyro)

PHPackages © 2026

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