PHP code example of iotronlab / filament-multi-guard

1. Go to this page and download the library: Download iotronlab/filament-multi-guard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iotronlab / filament-multi-guard example snippets


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

namespace App\FilamentTeams\Resources;

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

class Dashboard extends Page
{
    use ContextualPage;
}

namespace App\FilamentTeams\Resources;

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

class UserResource extends Resource
{
    use ContextualResource;
}

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());
                }
            });
        };
    }

// 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)
bash
php artisan make:filament-context FilamentTeams

app/FilamentTeams/Pages/
app/FilamentTeams/Resources/
app/FilamentTeams/Widgets/
app/Providers/FilamentTeamsServiceProvider.php
config/filament-teams.php
bash
php artisan make:filament-context FilamentTeams --guard
bash
php artisan make:filament-guard FilamentTeams 

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