PHPackages                             iotronlab/filament-multi-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. iotronlab/filament-multi-guard

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

iotronlab/filament-multi-guard
==============================

Multi Guard Context for Filament Admin

v1.0.1(3y ago)506.4k↓46.9%7[2 PRs](https://github.com/iotron/filament-multi-guard/pulls)MITPHPPHP ^8.0|^8.1

Since Oct 10Pushed 2y ago3 watchersCompare

[ Source](https://github.com/iotron/filament-multi-guard)[ Packagist](https://packagist.org/packages/iotronlab/filament-multi-guard)[ Docs](https://github.com/iotronlab/filament-multi-guard)[ RSS](/packages/iotronlab-filament-multi-guard/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (5)Dependencies (14)Versions (9)Used By (0)

**[filament-multi-guard](https://github.com/iotronlab/filament-multi-guard)**
=============================================================================

[](#filament-multi-guard)

[![Build Status](https://camo.githubusercontent.com/c59043e0b28eab034f19dabc49c9222c43e3fbe5e0c6bc2837a5c0086132a211/68747470733a2f2f7472617669732d63692e6f72672f6c61726176656c2f6672616d65776f726b2e737667)](https://travis-ci.org/laravel/framework)[![Total Downloads](https://camo.githubusercontent.com/0a0e54220da19dd15f82fe3b96e1e9748c22ac5cf6119c5c69798b061d1db188/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)[![Latest Stable Version](https://camo.githubusercontent.com/069cd9936142e0953278ec633f611230f20c46b42afd67b8b56724f51cd0ab74/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)[![License](https://camo.githubusercontent.com/03a3b51566430525c96e30c14ccc3f74ca39d3d4e18a7fedd49d16089a6a9d91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)[![Watcher](https://camo.githubusercontent.com/8cee493a2a71d43969fb0bf5dc50926ccd63e40d0767a7689beb0c5e046bab63/68747470733a2f2f62616467656e2e6e65742f6769746875622f77617463686572732f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)[![Release](https://camo.githubusercontent.com/7f9473fee717670440bbbd67a6bcf680a9509e7e1924fae808429d3f307035cd/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c656173652f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)[![Language](https://camo.githubusercontent.com/b76fa3c12c2980ef5eb087c30b12b3402bf9c7f52bb2c4781f0a85fd27a15fb9/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f6c616e672f696f74726f6e6c61622f66696c616d656e742d6d756c74692d6775617264)](https://packagist.org/packages/iotronlab/filament-multi-guard)

This features have been natively added to Filament v3. Use this package for v2 only!
------------------------------------------------------------------------------------

[](#this-features-have-been-natively-added-to-filament-v3-use-this-package-for-v2-only)

This package allows you to register multiple filament route/path based contexts in your application with their own set of resources, pages, widgets and guard. The contexts can also be used on the same guard instance. eg. for role based setups.

This package is derived from [filament-multi-context](https://github.com/artificertech/filament-multi-context) package but doesn't include it as a dependency as the package doesn't support multiple guard instances.

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

[](#installation)

You can install the package via composer:

```
composer require iotronlab/filament-multi-guard
```

Single Guard Usage
------------------

[](#single-guard-usage)

Create a new filament context **with out GuardLogin and GuardMiddleware.**

```
php artisan make:filament-context FilamentTeams
```

The above command will create the following files and directories:

```
app/FilamentTeams/Pages/
app/FilamentTeams/Resources/
app/FilamentTeams/Widgets/
app/Providers/FilamentTeamsServiceProvider.php
config/filament-teams.php

```

`Filament` cannot be passed as a context to this command as it is reserved for the default filament installation

> ***Register Provider:*** Be sure to add the `FilamentTeamsServiceProvider`class to your providers array in `config/app.php`

Multi Guard Usage
-----------------

[](#multi-guard-usage)

To create a new context **with GuardLogin and GuardMiddleware.**

```
php artisan make:filament-context FilamentTeams --guard
```

or make a GuardLogin and GuardMiddleware for a already generated context

```
php artisan make:filament-guard FilamentTeams
```

The above command will create the following files and directories:

```
app/FilamentTeams/Middleware/FilamentTeamsMiddleware.php
app/FilamentTeams/Pages/
app/FilamentTeams/Resources/
app/FilamentTeams/Widgets/
app/Http/Livewire/FilamentTeamsLogin.php
app/Providers/FilamentTeamsServiceProvider.php
config/filament-teams.php

```

`Filament` cannot be passed as a context to this command as it is reserved for the default filament installation

> ***Register Provider:*** Be sure to add the `FilamentTeamsServiceProvider`class to your providers array in `config/app.php`

Replace the auth guard, pages login and middleware auth in the context config with the **generated login page and middleware**.

```
use App\FilamentTeams\Middleware\FilamentTeamsMiddleware;
use App\Http\Livewire\FilamentTeamsLogin;

    'auth' => [
        'guard' => 'your-custom-guard',
        'pages' => [
            'login' => FilamentTeamsLogin::class,
        ],
    ],

     'middleware' => [
        'auth' => [
            // Authenticate::class,
            FilamentTeamsMiddleware::class
        ],

    ],

```

Now, you can go to /{context-path}/login to login to the new context. You can remove the ***dashboard*** from 'pages' in the context pages folder and implement your own dashboard.

You should implement the **logout** components UserMenuItem in a service provider with Filament::serving()

```
Filament::serving(function () {
    Filament::forContext('filament-teams', function () {
            Filament::registerUserMenuItems([
                'logout' => UserMenuItem::make()->label('Log Out')->url(route('filament-teams.logout')),
                ]);
            });
        });
```

Adding Pages/Resources to context
---------------------------------

[](#adding-pagesresources-to-context)

You may now add filament resources in your FilamentTeams directories. Generate Filament pages/resources/widgets as you normally would. Move them into the context-folder and update the namespace.

> ***Context Traits:*** be sure to add the ContextualPage and ContextualResource traits to their associated classes inside of your context directories. Without this when filament generates navigation links it will try to use `filament.pages.*` and `filament.resources.{resource}.*` instead of `{context}.pages.*` and `{context}.resources.{resource}.*` as the route names

### ContextualPage &amp; ContextualResource traits

[](#contextualpage--contextualresource-traits)

Pages:

```
namespace App\FilamentTeams\Resources;

use Iotronlab\FilamentMultiGuard\Concerns\ContextualPage;
use Filament\Pages\Page;

class Dashboard extends Page
{
    use ContextualPage;
}
```

Resources:

```
namespace App\FilamentTeams\Resources;

use Iotronlab\FilamentMultiGuard\Concerns\ContextualResource;
use Filament\Resources\Resource;

class UserResource extends Resource
{
    use ContextualResource;
}
```

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

[](#configuration)

The `config/filament-teams.php` file contains a subset of the `config/filament.php` configuration file. The values in the `filament-teams.php`file can be adjusted and will only affect the pages, resources, widgets, and auth guard for the `filament-teams` context.

Currently the configuration values that can be modified for a specific context are:

```
'path'
'domain'
'pages'
'resources'
'widgets'
'livewire'
'auth'
'middleware'

```

### ContextServiceProvider

[](#contextserviceprovider)

Your `ContextServiceProvider` found in your `app/Providers/FilamentTeamsServiceProvider.php` is an extension of the Filament `PluginServiceProvder` so features of the `PluginServiceProvider` may be used for your context

### Custom Page and Resource Routing

[](#custom-page-and-resource-routing)

If you would like more control over the way pages and resources are routed you may override the `componentRoutes()` function in your `FilamentTeamsServiceProvider`

```
protected function componentRoutes(): callable
    {
        return function () {
            Route::name('pages.')->group(function (): void {
                foreach (Facades\Filament::getPages() as $page) {
                    Route::group([], $page::getRoutes());
                }
            });

            Route::name('resources.')->group(function (): void {
                foreach (Facades\Filament::getResources() as $resource) {
                    Route::group([], $resource::getRoutes());
                }
            });
        };
    }
```

The Filament Facade
-------------------

[](#the-filament-facade)

In order for this package to work the `filament` app service has been overriden. Each context is represented by its own `FilamentMultiGuard\ContextManager` extending `Filament\FilamentManager` object. Within your application calls to the filament facade (such as `Filament::serving`) will be proxied to the appropriate `Filament\FilamentManager` object based on the current context of your application (which is determined by the route of the request)

### Context Functions

[](#context-functions)

The following functions have been added to facilitate multiple `Filament\FilamentManger` objects in your application:

```
// retrieve the string name of the current application context
// defaults to `filament`

Filament::currentContext(): string
```

```
// retrieve the Filament\FilamentManager object for the current app context

Filament::getContext()
```

```
// retrieve the array of Filament\FilamentManager objects keyed by the context name

Filament::getContexts()
```

```
// set the current app context.
// Passing null or nothing sets the context to 'filament'

Filament::setContext(string|null $context)
```

```
// sets the context for the duration of the callback function, then resets it back to the original value
Filament::forContext(string $context, function () {
    // ...
})
```

```
// loops through each registered context (including the default 'filament' context),
// sets that context as the current context,
// runs the callback, then resets to the original value
Filament::forAllContexts(function () {
    // ...
})
```

```
// creates a new FilamentManager object and registers it under the $name context
// this method is used by your ContextServiceProvider to register your context
// you shouldn't need to use this method during normal development
Filament::addContext(string $name)
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [iotron](https://github.com/iotronlab)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

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

Every ~35 days

Total

5

Last Release

1221d ago

PHP version history (3 changes)v1.0.0-alphaPHP ^8.1

v1.0.0-beta.2PHP ^8.0

v1.0.0PHP ^8.0|^8.1

### Community

Maintainers

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

---

Top Contributors

[![iotron](https://avatars.githubusercontent.com/u/50877415?v=4)](https://github.com/iotron "iotron (47 commits)")[![krishzzi](https://avatars.githubusercontent.com/u/36711704?v=4)](https://github.com/krishzzi "krishzzi (23 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")[![iotronlab](https://avatars.githubusercontent.com/u/219162761?v=4)](https://github.com/iotronlab "iotronlab (3 commits)")

---

Tags

filamentfilamentphplaravellaravel-frameworklaravelfilamentfilament-multi-contextiotronlabfilament-multi-guard

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/iotronlab-filament-multi-guard/health.svg)

```
[![Health](https://phpackages.com/badges/iotronlab-filament-multi-guard/health.svg)](https://phpackages.com/packages/iotronlab-filament-multi-guard)
```

###  Alternatives

[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[stephenjude/filament-jetstream

A Laravel starter kit built with Filament inspired by Jetstream.

17760.2k3](/packages/stephenjude-filament-jetstream)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[croustibat/filament-jobs-monitor

Background Jobs monitoring like Horizon for all drivers for FilamentPHP

274327.0k8](/packages/croustibat-filament-jobs-monitor)

PHPackages © 2026

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