PHPackages                             evansims/openfga-laravel - 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. evansims/openfga-laravel

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

evansims/openfga-laravel
========================

Stop writing authorization logic. Start asking questions. OpenFGA high performance relationship-based access control for Laravel.

v1.0.0(10mo ago)111.7k—0%3[5 issues](https://github.com/evansims/openfga-laravel/issues)[2 PRs](https://github.com/evansims/openfga-laravel/pulls)Apache-2.0PHPPHP ^8.3CI passing

Since Jul 5Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/evansims/openfga-laravel)[ Packagist](https://packagist.org/packages/evansims/openfga-laravel)[ Docs](https://github.com/evansims/openfga-laravel)[ RSS](/packages/evansims-openfga-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (15)Versions (13)Used By (0)

[![](.github/openfga.png)](https://openfga.dev)

OpenFGA Laravel SDK
===================

[](#openfga-laravel-sdk)

Stop writing authorization logic. Start asking questions.

**Every app needs permissions.** Most developers end up with authorization logic scattered across controllers, middleware, and business logic. Changes break things. New features require touching dozens of files.

**[OpenFGA](https://openfga.dev/) solves this.** Define your authorization rules once, query them anywhere. This package provides complete integration of [OpenFGA](https://openfga.dev/) and [Auth0 FGA](https://auth0.com/fine-grained-authorization) for Laravel applications.

- **Eloquent Integration** - Authorization methods on your models
- **Middleware Protection** - Secure routes with permission checks
- **Blade Directives** - Show/hide UI based on permissions
- **Testing Utilities** - Fake permissions in your tests
- **Performance Optimized** - Built-in caching and batch operations
- **Queue Support** - Async permission operations
- **Multi-tenancy Ready** - Multiple stores and connections
- **Type Safe** - PHP 8.3+ with strict typing and comprehensive generics
- **Developer Friendly** - Enhanced IDE support with detailed PHPDoc annotations

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

[](#installation)

```
composer require evansims/openfga-laravel
```

Publish the configuration:

```
php artisan vendor:publish --tag="openfga-config"
```

Set your environment variables:

```
OPENFGA_URL=http://localhost:8080
OPENFGA_STORE_ID=your-store-id
```

Usage Patterns
--------------

[](#usage-patterns)

```
// Controllers - Type-safe permission checks
if (cannot('edit', $document)) {
    abort(403);
}

// Middleware - Strict parameter validation
Route::put('/documents/{document}', [DocumentController::class, 'update'])
    ->middleware('openfga:editor,document:{document}');

// Blade Views - Enhanced type safety
@can('edit', 'document:' . $document->id)
    Edit
@endcan

// Eloquent Models - Comprehensive type annotations
$document->grant($user, 'editor');  // Grant permission
$document->check($user, 'editor');  // Check permission
$document->revoke($user, 'editor'); // Revoke permission

// Query by permissions - Generic return types
$myDocuments = Document::whereUserCan($user, 'edit')->get();
```

Quickstart
----------

[](#quickstart)

Let's implement a simple document sharing system with enhanced type safety.

```
