{"id":13733596,"url":"https://github.com/artificertech/filament-multi-context","last_synced_at":"2025-05-08T09:32:37.059Z","repository":{"id":40422355,"uuid":"483287218","full_name":"artificertech/filament-multi-context","owner":"artificertech","description":"A package for adding multiple contexts to the filament admin panel","archived":true,"fork":false,"pushed_at":"2023-07-03T06:58:03.000Z","size":94,"stargazers_count":86,"open_issues_count":7,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-03T13:47:40.512Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/artificertech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-04-19T14:44:24.000Z","updated_at":"2024-08-20T06:44:21.000Z","dependencies_parsed_at":"2024-02-03T02:43:40.845Z","dependency_job_id":"a82c2243-c093-4de6-ac28-ec5ffc193e4d","html_url":"https://github.com/artificertech/filament-multi-context","commit_stats":{"total_commits":48,"total_committers":8,"mean_commits":6.0,"dds":0.625,"last_synced_commit":"c7d37dff61ce40ba7113d4e6df58b7fdbf8af944"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artificertech%2Ffilament-multi-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artificertech%2Ffilament-multi-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artificertech%2Ffilament-multi-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artificertech%2Ffilament-multi-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artificertech","download_url":"https://codeload.github.com/artificertech/filament-multi-context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224720739,"owners_count":17358475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:46.012Z","updated_at":"2024-11-15T02:31:16.312Z","avatar_url":"https://github.com/artificertech.png","language":"PHP","funding_links":[],"categories":["MISC"],"sub_categories":[],"readme":"# A package for adding multiple contexts to the filament admin panel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/artificertech/filament-multi-context.svg?style=flat-square)](https://packagist.org/packages/artificertech/filament-multi-context)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/artificertech/filament-multi-context/run-tests?label=tests)](https://github.com/artificertech/filament-multi-context/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/artificertech/filament-multi-context/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/artificertech/filament-multi-context/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/artificertech/filament-multi-context.svg?style=flat-square)](https://packagist.org/packages/artificertech/filament-multi-context)\n\nThis package allows you to register multiple filament contexts in your\napplication with their own set of resources and pages\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require artificertech/filament-multi-context\n```\n\n## Usage\n\ncreate a new filament context using\n\n```bash\nphp artisan make:filament-context FilamentTeams\n```\n\nThe above command will create the following files and directories:\n\n```\napp/FilamentTeams/Pages/\napp/FilamentTeams/Resources/\napp/FilamentTeams/Widgets/\napp/Providers/FilamentTeamsServiceProvider.php\nconfig/filament-teams.php\n```\n\n`Filament` cannot be passed as a context to this command as it is reserved for\nthe default filament installation\n\n### **_Register Provider:_** \nBe sure to add the `FilamentTeamsServiceProvider` class to your providers array in `config/app.php`\n\n### Adding Resources and Pages\nYou may now add filament resources in your FilamentTeams directories.\n\n\u003e **_Context Traits:_** be sure to add the ContextualPage and ContextualResource\n\u003e traits to their associated classes inside of your context directories. (I\n\u003e tried really hard with v2 to make this unnecessary but sadly here we are).\n\u003e Without this when filament generates navigation links it will try to use\n\u003e `filament.pages.*` and `filament.resources.{resource}.*` instead of\n\u003e `{context}.pages.*` and `{context}.resources.{resource}.*` as the route names\n\n#### ContextualPage \u0026 ContextualResource traits\n\nPages:\n\n```php\nnamespace App\\FilamentTeams\\Pages;\n\nuse Artificertech\\FilamentMultiContext\\Concerns\\ContextualPage;\nuse Filament\\Pages\\Page;\n\nclass Dashboard extends Page\n{\n    use ContextualPage;\n}\n```\n\nResources:\n\n```php\nnamespace App\\FilamentTeams\\Resources;\n\nuse Artificertech\\FilamentMultiContext\\Concerns\\ContextualResource;\nuse Filament\\Resources\\Resource;\n\nclass UserResource extends Resource\n{\n    use ContextualResource;\n}\n```\n\n## Configuration\n\nThe `config/filament-teams.php` file contains a subset of the\n`config/filament.php` configuration file. The values in the `filament-teams.php`\nfile can be adjusted and will only affect the pages, resources, and widgets for\nthe `filament-teams` context.\n\nCurrently the configuration values that can be modified for a specific context\nare:\n\n```\n'path'\n'domain'\n'pages'\n'resources'\n'widgets'\n'livewire'\n'middleware'\n```\n\n### ContextServiceProvider\n\nYour `ContextServiceProvider` found in your\n`app/Providers/FilamentTeamsServiceProvider.php` is an extension of the Filament\n`PluginServiceProvder` so features of the `PluginServiceProvider` may be used\nfor your context. Any UserMenuItems, scripts, styles, or scriptData added to\nthe provider will be registered for that context only\n\n### Custom Page and Resource Routing\n\nIf you would like more control over the way pages and resources are routed you\nmay override the `componentRoutes()` function in your\n`FilamentTeamsServiceProvider`\n\n```php\nprotected function componentRoutes(): callable\n    {\n        return function () {\n            Route::name('pages.')-\u003egroup(function (): void {\n                foreach (Facades\\Filament::getPages() as $page) {\n                    Route::group([], $page::getRoutes());\n                }\n            });\n\n            Route::name('resources.')-\u003egroup(function (): void {\n                foreach (Facades\\Filament::getResources() as $resource) {\n                    Route::group([], $resource::getRoutes());\n                }\n            });\n        };\n    }\n```\n\n### Changing the context guard\n\nBy default all contexts will use the guard defined in the primary `filament.php`\nconfig file. However if you need to specify the guard for a specific context you\nmay add the following lines to your context config file:\n\n```php\n/*\n    |--------------------------------------------------------------------------\n    | Auth\n    |--------------------------------------------------------------------------\n    |\n    | This is the configuration that Filament will use to handle authentication\n    | into the admin panel.\n    |\n    */\n\n    'auth' =\u003e [\n        'guard' =\u003e 'my-custom-guard',\n    ],\n```\n\n## !!! The Filament Facade\n\nIn order for this package to work the `filament` app service has been overriden.\nEach context is represented by its own `Filament\\FilamentManager` object. Within\nyour application calls to the filament facade (such as `Filament::serving`) will\nbe proxied to the appropriate `Filament\\FilamentManager` object based on the\ncurrent context of your application (which is determined by the route of the\nrequest)\n\n### Context Functions\n\nThe following functions have been added to facilitate multiple\n`Filament\\FilamentManger` objects in your application:\n\n```php\n// retrieve the string name of the current application context\n// defaults to `filament`\n\nFilament::currentContext(): string\n```\n\n```php\n// retrieve the Filament\\FilamentManager object for the current app context\n\nFilament::getContext()\n```\n\n```php\n// retrieve the array of Filament\\FilamentManager objects keyed by the context name\n\nFilament::getContexts()\n```\n\n```php\n// set the current app context.\n// Passing null or nothing sets the context to 'filament'\n\nFilament::setContext(string|null $context)\n```\n\n```php\n// sets the context for the duration of the callback function, then resets it back to the original value\nFilament::forContext(string $context, function () {\n    // ...\n})\n```\n\n```php\n// loops through each registered context (including the default 'filament' context),\n// sets that context as the current context,\n// runs the callback, then resets to the original value\nFilament::forAllContexts(function () {\n    // ...\n})\n```\n\n```php\n// creates a new FilamentManager object and registers it under the $name context\n// this method is used by your ContextServiceProvider to register your context\n// you shouldn't need to use this method during normal development\nFilament::addContext(string $name)\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed\nrecently.\n\n## Contributing\n\nPlease see\n[CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for\ndetails.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report\nsecurity vulnerabilities.\n\n## Credits\n\n- [Cole Shirley](https://github.com/cole.shirley)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more\ninformation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartificertech%2Ffilament-multi-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartificertech%2Ffilament-multi-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartificertech%2Ffilament-multi-context/lists"}