laravelplus/fortress · v1.0.2

Fortress

Attribute-based authorization, declared on the method it protects. Roles, permissions, gates and ownership checks usually end up scattered across middleware and policies. Fortress puts them in one #[Authorize] attribute, next to the code.

use Laravelplus\Fortress\Attributes\Authorize;class PostController{    #[Authorize(        public: false,        roles: ['admin', 'editor'],        permissions: ['create', 'update'],        owner: App\Models\Post::class,        overrideKey: 'author_id'    )]    public function update(Request $request, $id)    {        // Update logic    }}
Installs1,999
Latestv1.0.2
PHP8.2+
Laravel11
A.MIT licensedMaintained by After.si

Powerful tools out of the box.

Roles, permissions, gates and ownership checks usually end up scattered across middleware and policies. Fortress puts them in one #[Authorize] attribute, next to the code.

#[Authorize] attribute

Roles, permissions, gates and ownership in one declarative attribute.

Roles & permissions

Allow a method when the user holds one of the listed roles or permissions.

Ownership checks

Compare a model's owner key with the signed-in user, with a per-method override key.

Laravel gates

Reuse the gates you already define, by name.

Public endpoints

Mark a method public: true and it skips the checks entirely.

Configurable

Default ownership keys, gates and behaviour live in config/fortress.php.

Set up Fortress and start using it today.

Requires PHP 8.2+ and Laravel 11. Every step copies with one click.

Step 1
$ composer require laravelplus/fortress
Step 2
$ php artisan vendor:publish --provider="Laravelplus\\Fortress\\FortressServiceProvider"

The details.

01

One middleware

Append AttributeAuthorizationMiddleware to the web group once. From then on every controller method is checked against its own attribute.

02

Less middleware clutter

No stack of route middleware per endpoint: the rule reads where the method is, and a reviewer sees it in the same diff.

More packages.