PHPackages                             typetomamun/laravel-event-guard - 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. typetomamun/laravel-event-guard

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

typetomamun/laravel-event-guard
===============================

Multi-tenant permission and role management for Laravel applications. Manage permissions for multiple shops, forums, groups, and more.

v1.0.0(5mo ago)01MITPHPPHP &gt;=8.2

Since Nov 30Pushed 5mo agoCompare

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

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

Laravel EventGuard
==================

[](#laravel-eventguard)

[![Latest Version on Packagist](https://camo.githubusercontent.com/efb0e904161d6ae5092ee742b1aeef6854981cad39d3ffc944e7ef564faf462f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74797065746f6d616d756e2f6c61726176656c2d6576656e742d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/typetomamun/laravel-event-guard)[![Total Downloads](https://camo.githubusercontent.com/b5be4e290e199f03e04a5a78865971ffc794699f209ab705685189b2d25f6c10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74797065746f6d616d756e2f6c61726176656c2d6576656e742d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/typetomamun/laravel-event-guard)[![License](https://camo.githubusercontent.com/d1b9101c2fb94d60bdeec0e12a2c87d9afc1db41c02a34d042590689ae2abe40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74797065746f6d616d756e2f6c61726176656c2d6576656e742d67756172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/typetomamun/laravel-event-guard)

Multi-tenant permission and role management for Laravel 11 &amp; 12. Perfect for applications where users can create multiple shops, forums, groups, announcements, and more - each with their own isolated roles and permissions.

Features
--------

[](#features)

- 🏢 **Multi-Tenant Architecture**: Users can own multiple events (shops, forums, groups, etc.)
- 🔐 **Event-Scoped Permissions**: Roles and permissions isolated per event instance
- 👤 **Automatic Owner Detection**: Event owners automatically have all permissions
- 🎯 **Flexible Role System**: Assign roles globally or per event
- 🛡️ **Middleware Support**: Easy route protection with intuitive syntax
- 🎨 **Blade Directives**: Clean permission checks in views
- 🚀 **Zero Conflicts**: All tables and methods prefixed with `egd_`
- ⚡ **Laravel 11 &amp; 12 Compatible**: Built for modern Laravel

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

[](#installation)

```
composer require typetomamun/laravel-event-guard
```

Publish the config and migrations:

```
php artisan vendor:publish --tag=eventguard-config
php artisan vendor:publish --tag=eventguard-migrations
```

Run migrations:

```
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

### 1. Add Trait to User Model

[](#1-add-trait-to-user-model)

```
use TypeToMamun\LaravelEventGuard\Traits\EGDHasRoles;

class User extends Authenticatable
{
    use EGDHasRoles;
}
```

### 2. Create Event Types

[](#2-create-event-types)

```
use TypeToMamun\LaravelEventGuard\Models\EGDEventType;

EGDEventType::create([
    'name' => 'Shop',
    'slug' => 'shop',
]);
```

### 3. Create Events

[](#3-create-events)

```
use TypeToMamun\LaravelEventGuard\Models\EGDEvent;

$shop = EGDEvent::create([
    'event_type_id' => $shopType->id,
    'name' => 'My Awesome Shop',
    'slug' => 'my-awesome-shop',
    'owner_id' => auth()->id(),
]);
```

### 4. Assign Roles

[](#4-assign-roles)

```
// Assign user as manager of a specific shop
$user->egdAssignEventRole($shop, 'manager');

// Give direct permission
$user->egdGiveEventPermission($shop, 'manage products');
```

### 5. Protect Routes

[](#5-protect-routes)

```
// Only shop managers can access
Route::middleware(['egd.event.role:{shop},manager'])->group(function () {
    Route::get('/shops/{shop}/dashboard', [ShopController::class, 'dashboard']);
});

// Only users with specific permission
Route::middleware(['egd.event.permission:{shop},manage products'])->group(function () {
    Route::post('/shops/{shop}/products', [ProductController::class, 'store']);
});
```

### 6. Use in Blade

[](#6-use-in-blade)

```
@egdeventowner($shop)
    Settings
@endegdeventowner

@egdeventrole($shop, 'manager')
    Manage Staff
@endegdeventrole

@egdeventpermission($shop, 'manage products')
    Add Product
@endegdeventpermission
```

Documentation
-------------

[](#documentation)

### Available Methods

[](#available-methods)

#### Event-Scoped Methods

[](#event-scoped-methods)

```
// Check if user has role for specific event
$user->egdHasEventRole($shop, 'manager');

// Check if user has permission for specific event
$user->egdHasEventPermission($shop, 'manage products');

// Assign role to user for specific event
$user->egdAssignEventRole($shop, 'manager');

// Give permission to user for specific event
$user->egdGiveEventPermission($shop, 'edit products');

// Remove role from user for specific event
$user->egdRemoveEventRole($shop, 'staff');

// Check if user is event owner
$user->egdIsEventOwner($shop);

// Get all events of a type owned by user
$myShops = $user->egdGetEventsForType('shop');
```

#### Global Methods

[](#global-methods)

```
// Check global role
$user->egdHasRole('admin');

// Assign global role
$user->egdAssignRole('admin');

// Check global permission
$user->egdHasPermissionTo('manage system');
```

### Middleware

[](#middleware)

```
// Event-scoped role middleware
Route::middleware(['egd.event.role:{event},manager'])->group(function () {
    // Routes here
});

// Event-scoped permission middleware
Route::middleware(['egd.event.permission:{event},edit articles'])->group(function () {
    // Routes here
});

// Global role middleware
Route::middleware(['egd.role:admin'])->group(function () {
    // Routes here
});

// Global permission middleware
Route::middleware(['egd.permission:manage system'])->group(function () {
    // Routes here
});
```

### Blade Directives

[](#blade-directives)

```
{{-- Event-scoped directives --}}
@egdeventowner($event)
    {{-- Content for event owner --}}
@endegdeventowner

@egdeventrole($event, 'manager')
    {{-- Content for managers --}}
@endegdeventrole

@egdeventpermission($event, 'edit products')
    {{-- Content for users with permission --}}
@endegdeventpermission

{{-- Global directives --}}
@egdrole('admin')
    {{-- Content for admins --}}
@endegdrole

@egdpermission('manage system')
    {{-- Content for users with permission --}}
@endegdpermission
```

Use Cases
---------

[](#use-cases)

### Multi-Shop Platform

[](#multi-shop-platform)

```
// User creates multiple shops
$shop1 = EGDEvent::create([...], 'electronics-store', owner: $user);
$shop2 = EGDEvent::create([...], 'fashion-boutique', owner: $user);

// Assign staff to specific shops
$manager->egdAssignEventRole($shop1, 'manager');
$staff->egdAssignEventRole($shop1, 'staff');

// Permissions are isolated per shop
$manager->egdHasEventPermission($shop1, 'manage products'); // ✅ true
$manager->egdHasEventPermission($shop2, 'manage products'); // ❌ false
```

### Forum Platform

[](#forum-platform)

```
// User creates forum
$forum = EGDEvent::create([...], 'tech-forum', owner: $user);

// Assign moderators
$moderator->egdAssignEventRole($forum, 'moderator');

// Check permissions
if ($moderator->egdHasEventPermission($forum, 'delete posts')) {
    // Can delete posts in this forum
}
```

Configuration
-------------

[](#configuration)

Publish and customize the config file:

```
// config/egd_permission.php

return [
    'models' => [
        'event' => \TypeToMamun\LaravelEventGuard\Models\EGDEvent::class,
        'role' => \TypeToMamun\LaravelEventGuard\Models\EGDRole::class,
        // ...
    ],

    'event_types' => [
        'shop' => [
            'name' => 'Shop',
            'roles' => ['owner', 'manager', 'staff'],
            'permissions' => ['view', 'edit', 'delete', 'manage products'],
        ],
        // Add your custom event types
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on recent changes.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [TypeToMamun](https://github.com/typetomamun)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Support
-------

[](#support)

- 📧 Email:
- 🐛 Issues: [GitHub Issues](https://github.com/typetomamun/laravel-event-guard/issues)
- 📖 Documentation: [Full Documentation](https://github.com/typetomamun/laravel-event-guard/wiki)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance71

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c132841d6f3049ff193bb08592c713027936d8dcbefd18a96f20cd1a41e0f6b?d=identicon)[typetomamun](/maintainers/typetomamun)

---

Top Contributors

[![typetomamun](https://avatars.githubusercontent.com/u/96810577?v=4)](https://github.com/typetomamun "typetomamun (2 commits)")

### Embed Badge

![Health badge](/badges/typetomamun-laravel-event-guard/health.svg)

```
[![Health](https://phpackages.com/badges/typetomamun-laravel-event-guard/health.svg)](https://phpackages.com/packages/typetomamun-laravel-event-guard)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[olssonm/l5-very-basic-auth

Laravel stateless HTTP basic auth without the need for a database

1662.5M1](/packages/olssonm-l5-very-basic-auth)[stechstudio/laravel-jwt

Helper package that makes it easy to generate, consume, and protect routes with JWT tokens in Laravel

126117.6k](/packages/stechstudio-laravel-jwt)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)

PHPackages © 2026

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