PHPackages                             fxmonster/brandenburg - 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. fxmonster/brandenburg

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

fxmonster/brandenburg
=====================

Laravel Authentication Package

1.5.2(2y ago)0678MITPHPPHP &gt;=7.3

Since Nov 22Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Brandenburg
===========

[](#brandenburg)

Laravel Authorization Package

[![Latest Version on Packagist](https://camo.githubusercontent.com/91a06ef5a78e20b70c28eea9038786fccf7f598696e56019e7f0d7911f03f68c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f53696c76616e6974652f6272616e64656e627572672e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/silvanite/brandenburg)[![Build Status](https://camo.githubusercontent.com/599818b6d794463dd9bf89517888cf2e1d8f0c0b8e3a69c38221d5b385929dee/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f53696c76616e6974652f6272616e64656e627572672f6d61737465722e7376673f7374796c653d666f722d7468652d6261646765)](https://travis-ci.org/Silvanite/brandenburg)

A opinionated Authorization package to closely integrate with standard Laravel Gates. It differs from other authorization packages by using hard-coded permissions defined within gate policies, rather than duplicating them within the Database.

TLDR; This package provides Users with Roles which are granted access to permissions (Laravel Gates).

Package maintenance
-------------------

[](#package-maintenance)

Unfortunately I am no longer actively working in the Laravel ecosystem and as such am unable to maintian this package. If anyone would like to take over the maintenance of the package please get in touch (open an issue or contact me on [Twitter](https://twitter.com/m2de_io)).

Version compatibility
---------------------

[](#version-compatibility)

LaravelBrandenburg&lt;=5.7.x1.1.x&gt;=5.8.x1.2.x^6.01.3.x^7.01.4.x^8.01.5.xInstallation
------------

[](#installation)

```
composer require silvanite/brandenburg
```

This package uses auto-loading in Laravel 5.5 of both the service provider and the `BrandenburgPolicy` Facade

For Laravel 5.1 - 5.4 load the Service Provider and Facade.

```
// config/app.php
'providers' => [
    ...
    Silvanite\Brandenburg\Providers\BrandenburgServiceProvider::class,
];

'aliases' => [
    ...
    'BrandenburgPolicy' => Silvanite\Brandenburg\Facades\PolicyFacade::class,
],
```

Three additional tables are required to enable User Roles. These will be installed automatically when you run the migrations. See the migration in this repository's source code for details about the tables created.

```
php artisan migrate
```

If you are not going to use Brandenburg's default migrations, you should change the `ignoreMigrations` option in the configuration file. You may export the default migrations using:

```
php artisan vendor:publish --tag=brandenburg-config
```

Usage
-----

[](#usage)

This package provides two traits. The main trait is intended for your user model which enabled model relationships.

```
use Silvanite\Brandenburg\Traits\HasRoles;

class User
{
    use HasRoles;
    ...
}
```

The second Trait `ValidatesPermissions` can optionally be used in your AuthServiceProvider when writing Gates. It can be used to stop users from getting locked out or to make some permissions optional by allowing access to a permission if no user in the system has been given access to it.

```
// AuthServiceProvider.php

if ($this->nobodyHasAccess('create-articles')) {
    return true;
};

// Check if the user has access
...
```

### Creating Roles

[](#creating-roles)

Use the `Silvanite\Brandenburg\Role` model to create and manage user roles.

```
$editor = Silvanite\Brandenburg\Role::create([
    'name' => 'Editor',
    'slug' => 'editor',
]);
```

### Creating Permissions

[](#creating-permissions)

All Gates defined within your application will automatically be available as Permissions, there is no need/way to create these specifically in the database. Please see the [Laravel Gates documentation](https://laravel.com/docs/5.5/authorization#writing-gates) for additional information.

### Managing Roles and Permissions

[](#managing-roles-and-permissions)

All permissions are assigned by providing the key defined by your Gate. They can be granted and revoked.

```
// Grant access
$editor->grant('create-articles');

// Revoke access
$editor->revoke('create-articles');
```

A couple of additional helper methods provide a convenient way to manage permissions.

```
// Grant access to a set of permissions and remove all other permissions
$editor->setPermissions([
    'create-articles',
    'read-articles',
    'update-articles',
    'delete-articles',
]);

// Revoke all permissions
$editor->revokeAll();
```

You can see which permissions a given role has by accessing the `permissions` attribute.

```
$editorPermissions = $editor->permissions;

// returns ['create-articles', 'read-articles', 'update-articles', 'delete-articles']
```

### Assigning/Removing Roles

[](#assigningremoving-roles)

Roles can be assigned/removed directly from the User model (provided the `HasRoles` trait is used). You can either pass in the `Role` model or the slug of the role.

```
// Using slug
$user->assignRole('editor');
$user->removeRole('editor');

// Using model
use Silvanite\Brandenburg\Role;

$user->assignRole(Role::first());
$user->removeRole(Role::first());
```

There is also a helper method to sync roles (or you can simply use the eloquent relationship itself).

```
$user->setRolesById([1, 3, 4]);

// Same as
$user->roles()->sync([1, 3, 4]);
```

### Validating Access Rights

[](#validating-access-rights)

Within your Gate definition you can validate if a given user has access to a specific permission, which will be based on the user Role(s).

```
$canCreateArticle = $user->hasRoleWithPermission('create-articles');
```

Outside of your Gate definitions you should use the standard Laravel Gate methods and helpers to check if a user has access rights. See the [Laravel Documentation](https://laravel.com/docs/5.5/authorization#authorizing-actions-via-gates) for more details.

Contributing
------------

[](#contributing)

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Run the tests: `./vendor/bin/phpunit`
5. Push to the branch: `git push origin my-new-feature`
6. Submit a pull request

Support
-------

[](#support)

If you require any support please contact me on [Twitter](https://twitter.com/m2de_io) or open an issue on this repository.

License
-------

[](#license)

GPL

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.6% 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

Unknown

Total

1

Last Release

903d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd798ef4478ec11bfe6a54f17cd0feca6380d901670e7c44121fb9f5381262b3?d=identicon)[fxmonster](/maintainers/fxmonster)

---

Top Contributors

[![m2de](https://avatars.githubusercontent.com/u/17720020?v=4)](https://github.com/m2de "m2de (92 commits)")[![damieneskimo](https://avatars.githubusercontent.com/u/6678975?v=4)](https://github.com/damieneskimo "damieneskimo (4 commits)")[![mathieutu](https://avatars.githubusercontent.com/u/11351322?v=4)](https://github.com/mathieutu "mathieutu (2 commits)")[![patrickAsare](https://avatars.githubusercontent.com/u/8025627?v=4)](https://github.com/patrickAsare "patrickAsare (2 commits)")[![marcodewsign](https://avatars.githubusercontent.com/u/16756649?v=4)](https://github.com/marcodewsign "marcodewsign (2 commits)")[![samwrigley](https://avatars.githubusercontent.com/u/17161173?v=4)](https://github.com/samwrigley "samwrigley (1 commits)")[![thenabeel](https://avatars.githubusercontent.com/u/3117493?v=4)](https://github.com/thenabeel "thenabeel (1 commits)")[![bonzai](https://avatars.githubusercontent.com/u/98191?v=4)](https://github.com/bonzai "bonzai (1 commits)")[![tolawho](https://avatars.githubusercontent.com/u/12527881?v=4)](https://github.com/tolawho "tolawho (1 commits)")[![ChandlerVS](https://avatars.githubusercontent.com/u/31043300?v=4)](https://github.com/ChandlerVS "ChandlerVS (1 commits)")[![crumb1e](https://avatars.githubusercontent.com/u/18497168?v=4)](https://github.com/crumb1e "crumb1e (1 commits)")[![fxmonster](https://avatars.githubusercontent.com/u/13942239?v=4)](https://github.com/fxmonster "fxmonster (1 commits)")[![jeverington](https://avatars.githubusercontent.com/u/1991914?v=4)](https://github.com/jeverington "jeverington (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/fxmonster-brandenburg/health.svg)

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

###  Alternatives

[lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users.

2.3k16.4M48](/packages/lab404-laravel-impersonate)[santigarcor/laratrust

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

2.3k5.4M43](/packages/santigarcor-laratrust)[overtrue/laravel-follow

User follow unfollow system for Laravel.

1.2k404.7k5](/packages/overtrue-laravel-follow)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)

PHPackages © 2026

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