### Run Filament Tenancy Installation Command Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md After Composer installation, execute this Artisan command to set up the necessary files and configurations for Filament Tenancy within your Laravel application. ```bash php artisan filament-tenancy:install ``` -------------------------------- ### Install Filament Tenancy via Composer Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md This command adds the Filament Tenancy package to your PHP project using Composer, making it available for use. ```bash composer require tomatophp/filament-tenancy ``` -------------------------------- ### Register Filament Tenancy Plugin in Central Panel Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Integrate the `FilamentTenancyPlugin` into your main central Filament panel's configuration. Ensure the panel name matches your setup. ```php use TomatoPHP\FilamentTenancy\FilamentTenancyPlugin; ->plugin(FilamentTenancyPlugin::make()->panel('app')) ``` -------------------------------- ### Publish Filament Tenancy Migrations Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md This command publishes the database migration files for Filament Tenancy, which are necessary for setting up the database schema. ```bash php artisan vendor:publish --tag="filament-tenancy-migrations" ``` -------------------------------- ### Publish Filament Tenancy Configuration Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md This command publishes the configuration file for Filament Tenancy, allowing you to customize its settings. ```bash php artisan vendor:publish --tag="filament-tenancy-config" ``` -------------------------------- ### Publish Filament Tenancy Views Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md This command publishes the view files for Filament Tenancy, enabling customization of the UI. ```bash php artisan vendor:publish --tag="filament-tenancy-views" ``` -------------------------------- ### Publish Filament Tenancy Language Files Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md This command publishes the language translation files for Filament Tenancy, allowing for localization. ```bash php artisan vendor:publish --tag="filament-tenancy-lang" ``` -------------------------------- ### Add Tenancy Middleware to Laravel Application Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Include `InitializeTenancyByDomain` and `InitializeTenancyBySubdomain` middleware in your `bootstrap/app.php` file. These middleware are essential for handling tenant identification based on domain or subdomain. ```php use Stancl\Tenancy\Middleware\InitializeTenancyByDomain; use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain; ->withMiddleware(function (Middleware $middleware) { $middleware->group('universal', [ InitializeTenancyByDomain::class, InitializeTenancyBySubdomain::class ]); }) ``` -------------------------------- ### Add Dynamic Database Connection in config/database.php Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Define a 'dynamic' database connection in your `config/database.php` file. This connection will be used by Filament Tenancy to switch between tenant databases based on the active tenant. ```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') ]) : [] ], ... ], ``` -------------------------------- ### Create New Filament Panel for Tenancy Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Use this Artisan command to generate a new Filament panel. The name of this panel should correspond to the one specified in your central panel's `FilamentTenancyPlugin` configuration. ```bash php artisan filament:panel ``` -------------------------------- ### Register Filament Tenancy App Plugin in Tenancy Panel Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Within the newly created tenancy-specific Filament panel, register the `FilamentTenancyAppPlugin`. This activates tenancy features for that panel. ```php use TomatoPHP\FilamentTenancy\FilamentTenancyAppPlugin; ->plugin(FilamentTenancyAppPlugin::make()) ``` -------------------------------- ### Enable Tenant Impersonation in Filament Plugin Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Call the `allowImpersonate()` method on the `FilamentTenancyPlugin` instance to enable the impersonation feature, allowing administrators to log in as tenants. ```php use TomatoPHP\FilamentTenancy\FilamentTenancyPlugin; ->plugin( FilamentTenancyPlugin::make() ->panel('app') ->allowImpersonate() ) ``` -------------------------------- ### Configure Central Domain in .env Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md Add the `CENTRAL_DOMAIN` variable to your `.env` file, specifying the root domain for your central Filament panel. This is crucial for multi-database tenancy. ```.env CENTRAL_DOMAIN=tomatophp.test ``` -------------------------------- ### Clear Laravel Configuration Cache Source: https://github.com/tomatophp/filament-tenancy/blob/master/README.md After modifying configuration files like `config/database.php`, run this command to clear and re-cache your application's configuration, ensuring changes take effect. ```php php artisan config:cache ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.