PHP code example of artificertech / filament-multi-context
1. Go to this page and download the library: Download artificertech/filament-multi-context 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/ */
artificertech / filament-multi-context example snippets
namespace App\FilamentTeams\Pages;
use Artificertech\FilamentMultiContext\Concerns\ContextualPage;
use Filament\Pages\Page;
class Dashboard extends Page
{
use ContextualPage;
}
namespace App\FilamentTeams\Resources;
use Artificertech\FilamentMultiContext\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());
}
});
};
}
/*
|--------------------------------------------------------------------------
| Auth
|--------------------------------------------------------------------------
|
| This is the configuration that Filament will use to handle authentication
| into the admin panel.
|
*/
'auth' => [
'guard' => 'my-custom-guard',
],
// 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)