PHPackages                             sonphvl/authorization - 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. sonphvl/authorization

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

sonphvl/authorization
=====================

A package for authorization by roles and permissions via Gate

v1.1.1(2y ago)018MITPHP

Since Jan 26Pushed 2y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (0)

About
=====

[](#about)

This package provides a simple implementation for authorization base on Laravel Gate.

Implementation
--------------

[](#implementation)

### 1. Install the package

[](#1-install-the-package)

This command will install the package:

```
composer require sonphvl/authorization
```

The package required to publish migrations, so if the migrations are not automatically published, please run the following commands:

```
php artisan vendor:publish --tag=authorization-migrations
php artisan migrate
```

### 2. Publish assets (optional)

[](#2-publish-assets-optional)

If you want to publish assets for editing, run the following commands

```
php artisan vendor:publish --tag=authorization-middleware
php artisan vendor:publish --tag=authorization-config
```

### 3. Register the Service Provider

[](#3-register-the-service-provider)

Open config/app.php and add your service provider to the providers array.

```
'providers' => [
    // Other Package Service Providers...
    Sonphvl\Authorization\AuthorizationServiceProvider::class,

    //Application Service Providers
],
```

### 4. Apply Authorizable trait

[](#4-apply-authorizable-trait)

Add Authorizable trait to your Authenticatable model such as User model

```
namespace App\Models;

// Others imported classes
use Sonphvl\Authorization\Traits\Authorizable; //Add this line

class User extends Authenticatable
{
    use Authorizable; //Add this line

    //Your model content
}
```

### 5. Manage roles and permissions

[](#5-manage-roles-and-permissions)

You can map the roles and permissions at "/authorization":

```
route('authorization.index')
```

### 6. Apply

[](#6-apply)

Once you installed the package, a middleware alias named "authorize" is automatically registered.

#### About Authorize Middleware

[](#about-authorize-middleware)

When you apply the middleware, default permission name used is concatenated with route prefix, lowercase of controller name prefix and action name. For example, consider the following route:

```
Route::prefix('admin')->group(function () {
    Route::get('/users', [UserController::class, 'index']);
});
```

In the example route above, the package will call the following:

```
$controller->authorize('admin-user-index');
```

To customize the controller name prefix, add this line to your controller:

```
public $authorizePrefix = 'alternative';
```

By this, the package will call the following:

```
$controller->authorize('admin-alternative-index');
```

#### Apply to middleware groups

[](#apply-to-middleware-groups)

To apply "authorize" middleware to middleware groups, add this to your application .env

```
AUTHORIZATION_MIDDLEWARE_GROUPS=web,api
```

When middleware groups are registered, add this to your controller to ignore any function:

```
public $ignoredAutoAuthorize = ['index']; //To ignore index function from authorization
```

#### Apply to routes

[](#apply-to-routes)

To apply for a single route

```
Route::get('/users', [UserController::class, 'index'])->middleware(['authorize']);
```

To apply for multiple routes

```
Route::middleware(['authorize'])->group(function () {
    Route::get('/', function () {
        // Uses first & second middleware...
    });

    Route::get('/user/profile', function () {
        // Uses first & second middleware...
    });
});
```

#### Manually apply to a specific function

[](#manually-apply-to-a-specific-function)

To authorize a function, add this line at the top of your controller function:

```
class UserController extends Controller
{
    public function index()
    {
        $this->authorize('permission-name'); //Add this line

        //The rest of the function
    }
}
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

3

Last Release

888d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/616ed037ef684707f4255bb60b678179f9f3a605c5748b2b4622ad06a5b0f96b?d=identicon)[sonphvl](/maintainers/sonphvl)

---

Top Contributors

[![son-agl](https://avatars.githubusercontent.com/u/100652884?v=4)](https://github.com/son-agl "son-agl (23 commits)")

### Embed Badge

![Health badge](/badges/sonphvl-authorization/health.svg)

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

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

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