PHPackages                             denismitr/laravel-permissions - 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. denismitr/laravel-permissions

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

denismitr/laravel-permissions
=============================

Laravel Roles And Permissions Package with Teams support

v2.3(7y ago)440MITPHPPHP &gt;=7.1.0

Since Feb 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/denismitr/laravel-permissions)[ Packagist](https://packagist.org/packages/denismitr/laravel-permissions)[ RSS](/packages/denismitr-laravel-permissions/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (9)Versions (11)Used By (0)

Version 2.1
-----------

[](#version-21)

Laravel Permissions
-------------------

[](#laravel-permissions)

This is a package to integrate with Laravel 5.5 - 5.8

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

[](#installation)

Require this package with composer:

```
composer require denismitr/laravel-permissions
```

After updating composer, add the `PermissionsServiceProvider` to the providers array in `config/app.php` like so:

```
Denismitr\Permissions\PermissionsServiceProvider::class,
```

Then if you need to use one of the provided middleware, you can add a `auth.group` middleware to your Http `Kernel.php` like so:

```
'auth.group.all' => \Denismitr\Permissions\Middleware\AuthGroupAllMiddleware::class,
'auth.group.any' => \Denismitr\Permissions\Middleware\AuthGroupAnyMiddleware::class,
```

This one insures that user belongs to all required auth groups

### Publish config and migrations

[](#publish-config-and-migrations)

```
php artisan vendor:publish
```

and pick `Provider: Denismitr\Permissions\PermissionsServiceProvider` from the list

### Migration

[](#migration)

Then run `php artisan migrate` and the following *5* tables will be created:

- auth\_groups
- permissions
- auth\_group\_users
- auth\_group\_permissions

Creating the **CRUD** and populating these tables is up to you.

Usage
-----

[](#usage)

First include `InteractsWithAuthGroups` trait into the `User` model like so:

```
use InteractsWithAuthGroups;
```

To add users to an AuthGroup and give them group permissions:

```
// Given we have
AuthGroup::create(['name' => 'superusers']);

// To find an auth group by name
AuthGroup::named('superusers')->addUser($userA)->addUser($userB);

$userA->isOneOf('superusers'); //true
$userB->isOneOf('superusers'); // true

// Gives permission to the choosen group
AuthGroup::named('superusers')->givePermissionTo($editArticlesPermission);
AuthGroup::named('superusers')->givePermissionTo($editBlogPermission);

// These methods check if user has a permission through any auth group,
// to which user belongs
$userA->hasPermissionTo('edit-articles'); // true
$userA->isAllowedTo('edit-blog'); // true

$userB->hasPermissionTo('edit-blog'); // true
$userB->isAllowedTo('edit-articles'); // true
```

##### Check if auth group already exists

[](#check-if-auth-group-already-exists)

```
AuthGroup::existsWithName('accountants'); // returns true or false
```

#### Private groups and/or teams

[](#private-groups-andor-teams)

User can create private groups or basically teams. Note that there is a `canOwnAuthGroups` method on `InteractsWithAuthGroups` trait that returns `true` by default. If you want to define some custom rules on whether this or that user is allowed to create auth groups, which you probably do, you need to override that method in your user model.

```
$privateGroup = $this->owner->createNewAuthGroup('My private group', 'My private group description');

$privateGroup
    ->addUser($this->userA)
    ->addUser($this->userB); // Custome role can be specified ->addUser($this->userB, 'accountant');

$authGroup->hasUser($this->userA); // true
$authGroup->isOwnedBy($this->owner); // true
$this->owner->ownsAuthGroup($authGroup); // true

$authGroup->forUser($this->userA)->allowTo('edit-articles');
```

#### Roles

[](#roles)

roles are just strings and they are supposed to be used just as additional helpers.

```
$user->onAuthGroup($privateGroup)->getRole(); // Owner (this one can be setup in config of the package)

$user->joinAuthGroup($bloggers, 'Invited user');
$user->joinAuthGroup($editors, 'Supervisor');

$user->onAuthGroup($editors)->getRole(); // 'Invited user'
$user->onAuthGroup($privateGroup)->getRole(); // 'Supervisor'

$user->onAuthGroup($bloggers)->hasRole('Invited user'); // true
$user->onAuthGroup($editors)->hasRole('Supervisor'); // true
$user->onAuthGroup($privateGroup)->hasRole('Pinguin'); // false
```

#### To withdraw permissions

[](#to-withdraw-permissions)

```
$authGroup->revokePermissionTo('delete post', 'edit post');
```

#### Grant permission through auth group:

[](#grant-permission-through-auth-group)

```
$admin->joinAuthGroup('admins'); // group must already exist

$admin->onAuthGroup('admins')->grantPermissionTo('administrate-blog'); // permission must already exist
// same as
$admin->onAuthGroup('admins')->allowTo('administrate-blog'); // permission must already exist
// or
$admin->onAuthGroup('admins')->givePermissionTo('administrate-blog');

// later

$blogAdminPermission->isGrantedFor($this->admin);
```

#### To check for permissions:

[](#to-check-for-permissions)

```
$user->hasPermissionTo('edit post', 'delete post');
$user->can('delete post');
```

Attention!!! for compatibility reasons the `can` method can support only single ability argument

### Current AuthGroup

[](#current-authgroup)

User can have a current auth group, via a `current_auth_group_id` column that is being added to the `users`table by the package migrations. This feature can be used to emulate switching between **teams** for example.

```
// Given
$user = User::create(['email' => 'new@user.com']);
$authGroupA = AuthGroup::create(['name' => 'Auth group A']);
$authGroupB = AuthGroup::create(['name' => 'Auth group B']);

// Do that
$user->joinAuthGroup($authGroupA);
$user->joinAuthGroup($authGroupB);

// Expect user is on two authGroups
$user->isOneOf($authGroupA); // true
$user->isOneOf($authGroupB); // true

// Do switch to authGroupB
$user->switchToAuthGroup($authGroupB);

// currentAuthGroup() method returns a current AuthGroup model or null in case user is
// not a member of any group
// currentAuthGroupName() works in the same way and can be used to display current team or group name
$user->currentAuthGroup(); // $authGroupB
$user->currentAuthGroupName(); // Auth group B
```

Note that in case user belongs to one or more **auth groups** the `currentAuthGroup()` method will automatically choose and set one of the users auth group as current, persist it on `User` model via `current_auth_group_id` column and return it. The same applies to `currentAuthGroupName()`.

Plus a bonus a **blade** `authgroup` and `team` directives:

```
@authgroup('staff')
// do stuff
@endauthgroup
```

And it's alias

```
@team('some team')
// do stuff
@endteam
```

Some other directives

```
@isoneof('admins')
...
@endisoneof

@isoneofany('writers|bloggers')
...
@endisoneofany
```

```
@isoneofall('authors,writers,bloggers')
...
@endisoneofall
```

### Author

[](#author)

Denis Mitrofanov

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Recently: every ~81 days

Total

10

Last Release

2595d ago

Major Versions

1.3.0 → v2.x-dev2018-07-01

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

v2.x-devPHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d68ae5d5ca94f49a69f961a7825865d92247b09e276a25fcc6ad485d4c8c964?d=identicon)[denismitr](/maintainers/denismitr)

---

Top Contributors

[![denismitr](https://avatars.githubusercontent.com/u/16356446?v=4)](https://github.com/denismitr "denismitr (70 commits)")

---

Tags

authorizationlaravellaravel-permissionsmiddlewareteamssecurityaclrolespermissionsTeamsdenismitr

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/denismitr-laravel-permissions/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k98.0M1.3k](/packages/spatie-laravel-permission)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.7k](/packages/larastan-larastan)[laravel/ai

The official AI SDK for Laravel.

1.0k2.1M163](/packages/laravel-ai)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9772.3M122](/packages/roots-acorn)

PHPackages © 2026

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