PHPackages                             andrewdyer/gate - 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. andrewdyer/gate

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

andrewdyer/gate
===============

Check if a user is authorized to perform a given action

1.0.1(1y ago)019[1 PRs](https://github.com/andrewdyer/gate/pulls)MITPHPPHP ^7.2.5

Since Feb 22Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (3)Versions (4)Used By (0)

Gate
====

[](#gate)

[![Latest Stable Version](https://camo.githubusercontent.com/25c647ada56ca4792b8421d29fb3e8b909787dd4f8daf01c1c05ed0c8a46f9b1/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f762f737461626c65)](https://packagist.org/packages/andrewdyer/gate)[![Total Downloads](https://camo.githubusercontent.com/6851e2b12ed17fb66f5a4b054da913a68284a9f9a7a80bb9404f7c21a94fde8d/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f646f776e6c6f616473)](https://packagist.org/packages/andrewdyer/gate)[![Daily Downloads](https://camo.githubusercontent.com/fee48253d6c1ab1de53a5238b95200d567f94e4309c47d8ed183c32454907d3b/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f642f6461696c79)](https://packagist.org/packages/andrewdyer/gate)[![Monthly Downloads](https://camo.githubusercontent.com/bbd804854ad932e1598d93f22725fda26d28d103449be540a22bc3c4c0428307/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f642f6d6f6e74686c79)](https://packagist.org/packages/andrewdyer/gate)[![Latest Unstable Version](https://camo.githubusercontent.com/178374e1b8ae6aa6e42d15cda8a2b7fc842d106660f28a525097f4ba97beb123/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f762f756e737461626c65)](https://packagist.org/packages/andrewdyer/gate)[![License](https://camo.githubusercontent.com/f7091c0a2dd641c570148a22aa55186cdff17220d17a13f1c50e9ab9884cf67b/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f6c6963656e7365)](https://packagist.org/packages/andrewdyer/gate)[![composer.lock](https://camo.githubusercontent.com/7ec5330c4802f1318621e873d4acc411f83458673de6cfb11ad3daa4aa0ef955/68747470733a2f2f706f7365722e707567782e6f72672f616e64726577647965722f676174652f636f6d706f7365726c6f636b)](https://packagist.org/packages/andrewdyer/gate)

Check if a user is authorized to perform a given action.

License
-------

[](#license)

Licensed under MIT. Totally free for private or commercial projects.

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

[](#installation)

```
composer require andrewdyer/gate

```

Getting Started
---------------

[](#getting-started)

To get started with the Gate library, you need to create an instance of the `Gate` class and pass an `Authenticatable` user to it.

```
use Anddye\Gate\Gate;
use Anddye\Gate\Authenticatable;

class User implements Authenticatable {
    // User implementation
}

$user = new User();
$gate = new Gate($user);
```

Usage
-----

[](#usage)

### Defining Abilities

[](#defining-abilities)

You can define abilities using the `define` method. The first argument is the name of the ability, and the second argument is a callback that determines if the user has the ability.

```
$gate->define('edit-post', function ($user, $post) {
    return $user->id === $post->user_id;
});
```

### Checking Abilities

[](#checking-abilities)

You can check abilities using the `allows` and `denies` methods.

```
if ($gate->allows('edit-post', $post)) {
    // The user can edit the post
}

if ($gate->denies('edit-post', $post)) {
    // The user cannot edit the post
}
```

### Authorizing Actions

[](#authorizing-actions)

You can authorize actions using the `authorize` method. This method will throw an `UnauthorizedException` if the user does not have the required abilities.

```
try {
    $gate->authorize(['edit-post'], $post);
    // The user is authorized to edit the post
} catch (UnauthorizedException $e) {
    // The user is not authorized to edit the post
}
```

### Registering Before Callbacks

[](#registering-before-callbacks)

You can register a callback to run before all checks using the `before` method.

```
$gate->before(function ($user, $ability) {
    if ($user->isAdmin()) {
        return true;
    }
});
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance40

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Total

2

Last Release

511d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/666597ea6e46748a89fe8764d1a45b4d0da97daf1bb1e9770ea34ae41f706d08?d=identicon)[andrewdyer](/maintainers/andrewdyer)

---

Top Contributors

[![andrewdyer](https://avatars.githubusercontent.com/u/8114523?v=4)](https://github.com/andrewdyer "andrewdyer (6 commits)")

---

Tags

authorizationgatepermissionsphpphpauthorizationpermissionsgate

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/andrewdyer-gate/health.svg)

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

###  Alternatives

[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.4M43](/packages/santigarcor-laratrust)[shanmuga/laravel-entrust

This package provides a flexible solution to add ACL to Laravel

68312.9k2](/packages/shanmuga-laravel-entrust)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)

PHPackages © 2026

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