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

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

amir/laravel-permission
=======================

an easy and flexible way for permissions management

v1.7.1(1y ago)475.0k↑50%11[3 issues](https://github.com/amiryousefi/laravel-permission/issues)[1 PRs](https://github.com/amiryousefi/laravel-permission/pulls)MITPHP

Since Apr 22Pushed 1y ago4 watchersCompare

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

READMEChangelog (10)DependenciesVersions (12)Used By (0)

Laravel permission
==================

[](#laravel-permission)

An easy and flexible Laravel authorization and roles permission management

Why we need a Laravel permission package
----------------------------------------

[](#why-we-need-a-laravel-permission-package)

In many projects, we need to implement a role-based permissions management system for our users. Although Laravel has the best tools to manage users' permissions, I build this package to make it simpler, more flexible, and to avoid duplicate work in many web projects built on Laravel.

How to use
----------

[](#how-to-use)

The idea is to use this package as easy and as flexible as possible.
This package creates a list of all your routes and assigns these permissions list to user roles.
Although the `laravel-permission` package does most of the work, you could easily extend it and implement your authorization system.

### Installation

[](#installation)

Start with installing the package through the composer. Run this command in your terminal:

```
$ composer require amir/laravel-permission

```

After that, you need to run the migration files:

```
$ php artisan migrate

```

### How to authorize user

[](#how-to-authorize-user)

This package adds a `role_id` to the `users` table. Roles are stored in the `roles` table. You can assign a role to a user in your administrator panel or by creating a seed file.
Then, you only need to assign `auth.role` middleware to your routes.

### Assign a route to a role

[](#assign-a-route-to-a-role)

Besides middleware and other route settings, you can use a `role` key in your route groups to assign a role to your routes.
You can put your routes for a role in a `Route` group like this:

```
Route::group([
    'middleware' => 'auth.role',
    'prefix' => ...,
    'role' => ['admin', 'customer'],
    ...
],function (){
    ...
    Route::get('/home', 'HomeController@index')->name('home');
    Route::get('/product', 'ProductController@index');
    ...
});
```

Of course, you can have as many as route groups like this.
Then you need to run this artisan command to register all permissions:

```
$ php artisan permissions:generate

```

This command will register all permissions and assign permissions to the roles.
If you add a `fresh` option to this command, it will delete all data and generate fresh permissions data:

```
$ php artisan permissions:generate --fresh

```

Now only users with the proper role can access the route assigned to them.
Don't forget that this package does not handle assigning roles to the users. You need to handle this in your administration panel or anywhere else you handle your users.
Again, if you want to add permissions to the routes manually it is not necessary to add `role` key in your route group. You can easily assign permissions to the roles in your administration panel or create another seed file for that. ### How to create roles

[](#how-to-create-roles)

The `php artisan permissions:generate` command will make all roles defined in the routes if they are not exist.
Also, You can create a seeder to fill the `roles` table. It takes only a `name` field.
Your `RolesSeeser` file can look like this.

```
Role::firstOrCreate(['name' => 'admin']);
Role::firstOrCreate(['name' => 'customer']);
```

Don't forget to import the `Role` model in your seeder.

```
use Amir\Permission\Models\Role;
```

### How to clear permissions

[](#how-to-clear-permissions)

To clear registered permissions you can run this command:

```
$ php artisan permissions:clear

```

You can use this command to clear all permissions data for a specific role

```
$ php artisan permissions:clear --roles role1 role2

```

To erase only permissions list, run `permissions:clear` command with this option:

```
$ php artisan permissions:clear --tables permissions

```

To clear all roles:

```
$ php artisan permissions:clear --tables roles

```

To clear only permissions role relation:

```
$ php artisan permissions:clear --tables permission_role

```

This command erases all permissions assigned to roles, so you can regenerate permissions

Also, you can use these options in combination:

```
$ php artisan permissions:clear --roles admin --tables permission_role

```

About
-----

[](#about)

I used this Laravel permission management method in my projects for a while. It made manging Laravel permission easy and flexible for me. I hope it helps you as well. All pull requests are welcome.
Most of the work is based on my article about [Laravel authorization and roles permission management](https://medium.com/swlh/laravel-authorization-and-roles-permission-management-6d8f2043ea20)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 76.3% 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 ~169 days

Recently: every ~247 days

Total

11

Last Release

522d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/939029?v=4)[Amir Yousefi](/maintainers/amiryousefi)[@amiryousefi](https://github.com/amiryousefi)

---

Top Contributors

[![amiryousefi](https://avatars.githubusercontent.com/u/939029?v=4)](https://github.com/amiryousefi "amiryousefi (29 commits)")[![aahelali](https://avatars.githubusercontent.com/u/36162946?v=4)](https://github.com/aahelali "aahelali (6 commits)")[![asia-coder](https://avatars.githubusercontent.com/u/13574524?v=4)](https://github.com/asia-coder "asia-coder (1 commits)")[![a-yousefi](https://avatars.githubusercontent.com/u/70909001?v=4)](https://github.com/a-yousefi "a-yousefi (1 commits)")[![Hacklason](https://avatars.githubusercontent.com/u/39498755?v=4)](https://github.com/Hacklason "Hacklason (1 commits)")

---

Tags

laravellaravel-permission

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/amir-laravel-permission/health.svg)](https://phpackages.com/packages/amir-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)
