PHPackages                             webard/laravel-access-control - 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. [Database &amp; ORM](/categories/database)
4. /
5. webard/laravel-access-control

ActiveLibrary[Database &amp; ORM](/categories/database)

webard/laravel-access-control
=============================

A modular access control library for Laravel applications.

v1.1.1(4mo ago)7584—7.1%[1 PRs](https://github.com/webard/laravel-access-control/pulls)MITPHPPHP ^8.4CI passing

Since Jan 5Pushed 2mo agoCompare

[ Source](https://github.com/webard/laravel-access-control)[ Packagist](https://packagist.org/packages/webard/laravel-access-control)[ Docs](https://github.com/webard/access-control)[ GitHub Sponsors](https://github.com/webard)[ RSS](/packages/webard-laravel-access-control/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (6)Used By (0)

Laravel Access Control
======================

[](#laravel-access-control)

  ![Laravel Access Control](https://camo.githubusercontent.com/ac83f0974a9953861591e4ffcc6f8252e9ccc2df8cfba2ad22710401d1bbf5a2/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230416363657373253230436f6e74726f6c2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7765626172642532466c61726176656c2d6163636573732d636f6e74726f6c267061747465726e3d776967676c65267374796c653d7374796c655f31266465736372697074696f6e3d436f6e74726f6c2b6163636573732b7573696e672b456e756d732b616e642b5065726d697373696f6e2b566f74657273266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)[![Latest Version on Packagist](https://camo.githubusercontent.com/2b1f34aa9343493ac625e46238f6adf35e6de502b917ce14143c015fd4d217c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765626172642f6c61726176656c2d6163636573732d636f6e74726f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webard/laravel-access-control)[![Total Downloads](https://camo.githubusercontent.com/61c8b17350a3e3c7de35129f4b6a1520445b159558372645f3467e332ef8e4a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765626172642f6c61726176656c2d6163636573732d636f6e74726f6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webard/laravel-access-control)

A modular access control library for Laravel applications that uses **enum-based permissions** and a **voter system**. Perfect for modular monolith architectures where different modules can define their own permission logic and extend existing.

### Example

[](#example)

Imagine two modules: **Product** and **ProductGallery**. The Product module knows nothing about ProductGallery, but ProductGallery should block product deletion until all galleries are removed.

**Product module** defines the permission:

```
enum ProductPermission: string implements PermissionDefinition
{
    case Delete = 'product.delete';
}
```

**ProductGallery module** registers a voter to add its constraint:

```
// In ProductGalleryServiceProvider
$registry = resolve(VoterRegistry::class);

$registry->register(
    ProductPermission::Delete,

    function (User $user, Product $product = null): Response {
        if ($product && $product->galleries()->exists()) {
            return Response::deny('Cannot delete product with galleries.');
        }
        return Response::allow();
    }
);
```

This library allows achieving such behavior without tightly coupling the two modules.

Key Features
------------

[](#key-features)

- 🔐 **Enum-based permissions** - Define permissions as PHP enums for type-safety and IDE autocomplete
- 🗳️ **Voter system** - Replace Laravel Policies with flexible voters that can be registered from any module
- 📦 **Modular architecture** - Each module can register its own voters without modifying core logic
- 🏷️ **Permission metadata** - Add names, descriptions, and groups to permissions via PHP attributes
- ⚡ **Laravel Gate integration** - Works seamlessly with Laravel's authorization system

When to Use This Package
------------------------

[](#when-to-use-this-package)

This package is designed primarily for **modular monolith architectures** where your application is split into independent modules (e.g., using [nWidart/laravel-modules](https://github.com/nWidart/laravel-modules) or [InterNACHI/modular](https://github.com/InterNACHI/modular)).

The key advantage of this package is that **voters can be registered from any module**, allowing each module to define its own authorization constraints without modifying the core application or other modules.

### When NOT to Use This Package

[](#when-not-to-use-this-package)

If you're building a traditional Laravel monolith without modular architecture, you probably don't need this package. In that case, the following solutions are sufficient:

- **[Laravel Policies](https://laravel.com/docs/authorization#creating-policies)** - Built-in authorization system, perfect for simple applications
- **[spatie/laravel-permission](https://github.com/spatie/laravel-permission)** - Excellent package for role and permission management in monolithic applications

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 12.0+

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

[](#installation)

You can install the package via composer:

```
composer require webard/laravel-access-control
```

Usage
-----

[](#usage)

### 1. Define Permissions as Enums

[](#1-define-permissions-as-enums)

Create an enum that implements `PermissionDefinition`:

```
