PHPackages                             mayconbordin/entrust-middleware - 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. mayconbordin/entrust-middleware

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

mayconbordin/entrust-middleware
===============================

A Laravel 5 middleware for Entrust

8139PHP

Since Jul 27Pushed 9y ago3 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

entrust-middleware
==================

[](#entrust-middleware)

A Laravel 5 middleware for Entrust.

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

[](#installation)

In order to install entrust-middleware, just add

```
	"mayconbordin/entrust-middleware": "dev-master"
```

to your composer.json. Then run `composer install` or `composer update`.

Add the following line

```
'permissions' => 'Mayconbordin\Entrust\Middleware\Permissions'
```

to your `app/Http/Kernel.php` file in the `$routeMiddleware` array.

Ownership Resolver
------------------

[](#ownership-resolver)

To use the middleware you need to implement the `OwnershipResolverContract` and register the binding interface to your implementation.

The interface defines the method `hasOwnership($permission, $user, Route $route)`, which must return a boolean. The idea is that sometimes a permission is conditional, meaning that the user can only access or do something to certain resource if he is the owner of such resource.

Imagine, for example, a blog with multiple authors that can only edit their own posts. For the permission to be evaluated by the `OwnershipResolverContract` service it must have `-own-` in the name, in this case `edit-own-post`.

The implementation of the contract would look something like this:

```
class OwnershipResolver implements OwnershipResolverContract
{
    public function hasOwnership($permission, $user, Route $route)
    {
        if ($permission == 'edit-own-post') {
            $post = Post::find($route->getParameter("id"));

            if ($post->author->id == $user->id) return true;
        }

        return false;
    }
}
```

You then register the implementation on the `register` method of `AppServiceProvider`:

```
$this->app->bind(
    'Mayconbordin\Entrust\Middleware\Contracts\OwnershipResolverContract',
    'App\Services\OwnershipResolver'
);
```

Usage
-----

[](#usage)

To check for a permission in a route:

```
Route::put('/posts/{id}', [
    'uses'        => 'PostController@edit',
    'middleware'  => 'permissions',
    'permissions' => 'edit-own-post'
]);
```

Or you can check for a role instead:

```
Route::put('/posts/{id}', [
    'uses'       => 'PostController@edit',
    'middleware' => 'permissions',
    'roles'      => 'admin'
]);
```

You can also check for both permissions and roles:

```
Route::put('/posts/{id}', [
    'uses'        => 'PostController@edit',
    'middleware'  => 'permissions',
    'permissions' => 'edit-own-post',
    'roles'       => 'admin'
]);
```

In this case the user must have either the permission or the role. At last, you can also list more than one permission or role:

```
Route::put('/posts/{id}', [
    'uses'        => 'PostController@edit',
    'middleware'  => 'permissions',
    'permissions' => ['edit-post', 'edit-own-post']
]);
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/42528727c83dd30f55c2a01ced50c7f22aeaf5a0bf83503d862e15448733a81a?d=identicon)[mayconbordin](/maintainers/mayconbordin)

---

Top Contributors

[![mayconbordin](https://avatars.githubusercontent.com/u/597104?v=4)](https://github.com/mayconbordin "mayconbordin (2 commits)")

### Embed Badge

![Health badge](/badges/mayconbordin-entrust-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/mayconbordin-entrust-middleware/health.svg)](https://phpackages.com/packages/mayconbordin-entrust-middleware)
```

###  Alternatives

[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)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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