PHPackages                             jftecnologia/laravel-permission - 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. jftecnologia/laravel-permission

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

jftecnologia/laravel-permission
===============================

RBAC + scoped permissions (all/self/attached) for Laravel

002PHPCI passing

Since Feb 6Pushed 3mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Permission
==================

[](#laravel-permission)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5fbead1d1fab7ad5e61137d811e7d736778e97156a9ee1de61bfc8fb529c8b7c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a667465636e6f6c6f6769612f6c61726176656c2d7065726d697373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jftecnologia/laravel-permission)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5974f4a9103d3cf899d440745e9e8700c1235f417bb56be4637adf9cf6a44d6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a667465636e6f6c6f6769612f6c61726176656c2d7065726d697373696f6e2f74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jftecnologia/laravel-permission/actions?query=workflow%3Atests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/994d8412c47d3596cb71aded25c628d43038893767a17d2bb9dcd5745b45b11f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a667465636e6f6c6f6769612f6c61726176656c2d7065726d697373696f6e2f6669782d7068702d636f64652d7374796c652e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jftecnologia/laravel-permission/actions?query=workflow%3A%22fix-php-code-style-issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/91e722ca8b128b0f1a75a0105b65b8cb37940d7579eb72958f1d6804bb1afc78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a667465636e6f6c6f6769612f6c61726176656c2d7065726d697373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jftecnologia/laravel-permission)

RBAC for Laravel with scoped permissions (`all`, `self`, `attached`) and optional multi-tenancy support.

> **1:1 model:** the Gate ability string equals the permission name (e.g. `companies.edit.attached` == `permissions.name`).

Features
--------

[](#features)

- **Scoped permissions** with `all`, `self`, and `attached` scopes
- **Roles and permissions** with a familiar API
- **Attachment-based access** for fine-grained authorization
- **Optional multi-tenancy** via a feature flag
- **Configurable resolvers** for tenant and self resolution

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

[](#installation)

```
composer require jftecnologia/laravel-permission
```

Publish config (optional):

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

Run the migrations:

```
php artisan migrate
```

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

[](#configuration)

`config/permission.php`:

- `models.permission|role|attachment`: swap the Eloquent models
- `tables.*`: rename tables
- `tenancy.enabled`: feature flag for multi-tenancy (default: `true`)
- `tenancy.column`: tenant column name (default: `tenant_id`)
- `tenant_resolver`: callback to resolve the current tenant id (nullable)
- `self_resolver`: callback to define what "self" means

### Default self

[](#default-self)

If you don't define `self_resolver`, the package uses the convention:

- `resource->created_by == user->id`

Usage
-----

[](#usage)

### 1) On your User model

[](#1-on-your-user-model)

Add the trait:

```
use JuniorFontenele\LaravelPermission\Traits\InteractsWithPermissions;

class User extends Authenticatable
{
    use InteractsWithPermissions;
}
```

### 2) Create and assign permissions

[](#2-create-and-assign-permissions)

Permissions are unique strings (`permissions.name` is **unique**):

```
$user->givePermissionTo('companies.edit.all');
```

### 3) Roles

[](#3-roles)

```
$user->assignRole('editor');
$user->syncRoles(['editor', 'viewer']);
$user->removeRole('viewer');
```

Permission via role:

```
$role = \JuniorFontenele\LaravelPermission\Models\Role::query()->firstOrCreate([
    'tenant_id' => null,
    'name' => 'editor',
    'guard_name' => 'web',
]);

$role->givePermissionTo('companies.edit.all');
```

### 4) Gate/Policies (scopes)

[](#4-gatepolicies-scopes)

```
$user->can('companies.edit.all');
$user->can('companies.edit.self', $company);
$user->can('companies.edit.attached', $company);
```

- `all`: checks RBAC only
- `self`: RBAC + `self_resolver`
- `attached`: RBAC + `permission_attachments` record

### 5) Attachments (attached scope)

[](#5-attachments-attached-scope)

```
use JuniorFontenele\LaravelPermission\Facades\Permission;

Permission::attach($user, 'companies.edit.attached', $company);

$user->can('companies.edit.attached', $company); // true
```

Multi-tenancy
-------------

[](#multi-tenancy)

Multi-tenancy support is a **feature flag**:

- `permission.tenancy.enabled = true`: creates/uses tenant column in tables (migrations + queries)
- `permission.tenancy.enabled = false`: ignores tenant entirely and **does not** create the column

The column is configurable via `permission.tenancy.column` (default: `tenant_id`).

To enable tenant scoping, define `permission.tenant_resolver` in config (or pass `tenantId` explicitly in APIs).

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Junior Fontenele](https://github.com/juniorfontenele)

License
-------

[](#license)

MIT License. See [LICENSE.md](LICENSE.md) for details.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance55

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3694405?v=4)[Junior Fontenele](/maintainers/juniorfontenele)[@juniorfontenele](https://github.com/juniorfontenele)

---

Top Contributors

[![juniorfontenele](https://avatars.githubusercontent.com/u/3694405?v=4)](https://github.com/juniorfontenele "juniorfontenele (1 commits)")

### Embed Badge

![Health badge](/badges/jftecnologia-laravel-permission/health.svg)

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

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