https://github.com/tomatophp/filament-tenancy
Tenancy multi-database integration for FilamentPHP
https://github.com/tomatophp/filament-tenancy
filament-plugins multi-database-multi-tenancy tenancy-for-laravel tenancy-management
Last synced: about 1 year ago
JSON representation
Tenancy multi-database integration for FilamentPHP
- Host: GitHub
- URL: https://github.com/tomatophp/filament-tenancy
- Owner: tomatophp
- License: mit
- Created: 2024-08-21T10:09:57.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T14:47:45.000Z (over 1 year ago)
- Last Synced: 2025-03-29T17:03:12.608Z (about 1 year ago)
- Topics: filament-plugins, multi-database-multi-tenancy, tenancy-for-laravel, tenancy-management
- Language: PHP
- Homepage: https://tomatophp.com/en/open-source/filament-tenancy
- Size: 1.46 MB
- Stars: 48
- Watchers: 3
- Forks: 15
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-filamentphp - tomatophp/filament-tenancy - Tenancy multi-database integration for FilamentPHP. (Misc)
README

# Filament Tenancy
[](https://packagist.org/packages/tomatophp/filament-tenancy)
[](https://packagist.org/packages/tomatophp/filament-tenancy)
[](https://packagist.org/packages/tomatophp/filament-tenancy)
Tenancy multi-database integration for FilamentPHP
> [!WARNING]
> We have a known problem with `route:cache` if you find a problem with multi-database connection from your tenant side you may face this problem just use `php artisan route:clear` and it will be fixed.
## Screenshots




## Features
- [x] Multi Database
- [x] Create Tenant Resource
- [x] Sync Tenant Resource
- [x] Password Change
- [x] Tenant Impersonate
- [ ] Share Tenant Data
- [ ] Custom Theme For Tenant
- [ ] Livewire Component For Register New Tenant
## Installation
```bash
composer require tomatophp/filament-tenancy
```
after install your package please run this command
```bash
php artisan filament-tenancy:install
```
in your `.env` add this
```.env
CENTRAL_DOMAIN=tomatophp.test
```
where `tomatophp.test` is your central domain, and make sure you add a root user or a user have a permission to create database, then in your main central panel add this plugin
```php
use TomatoPHP\FilamentTenancy\FilamentTenancyPlugin;
->plugin(FilamentTenancyPlugin::make()->panel('app'))
```
now you need to create a panel for tenancy app
```bash
php artisan filament:panel
```
and make the name same as `->panel('app')`, in your tenancy app panel add this plugin
```php
use TomatoPHP\FilamentTenancy\FilamentTenancyAppPlugin;
->plugin(FilamentTenancyAppPlugin::make())
```
now on your `config\database.php` add this code
```php
...
'connections' => [
'dynamic' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
...
],
```
now run config:cache
```php
php artisan config:cache
```
on your `bootstrap\app.php` add this middleware
```php
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
->withMiddleware(function (Middleware $middleware) {
$middleware->group('universal', [
InitializeTenancyByDomain::class,
InitializeTenancyBySubdomain::class,
]);
})
```
## Allow Impersonate
you can allow impersonate to tanent panel with 1 click by use this method on your plugin
```php
use TomatoPHP\FilamentTenancy\FilamentTenancyPlugin;
->plugin(
FilamentTenancyPlugin::make()
->panel('app')
->allowImpersonate()
)
```
## Publish Assets
you can publish config file by use this command
```bash
php artisan vendor:publish --tag="filament-tenancy-config"
```
you can publish views file by use this command
```bash
php artisan vendor:publish --tag="filament-tenancy-views"
```
you can publish languages file by use this command
```bash
php artisan vendor:publish --tag="filament-tenancy-lang"
```
you can publish migrations file by use this command
```bash
php artisan vendor:publish --tag="filament-tenancy-migrations"
```
## Other Filament Packages
Checkout our [Awesome TomatoPHP](https://github.com/tomatophp/awesome)