Get Started
Requirements
PHP (8.1 or more)
Composer
Node.js and npm
MySQL
Deploy project
1. Clone repository
2. Install composer and npm requirements
3. Setup environment file
Configure database connection settings and other necessary settings in .env.
4. Web server setup
Setup .htaccess for apache in ./public
5. Create robots.txt
(if on public server)
6. Generate application key
7. Run database migrations
8. Link the storage
9. Build JS/CSS assets
10. Run tests (optional)
11. Operations with tenants
General description of tenants
The project uses a multi-tenant architecture that allows serving multiple clients (tenants) on a single codebase, each with its own database. This enables data separation between clients while maintaining unified application logic. Tenant implementation is based on database connection switching that occurs with each request. The current tenant can be determined in two ways:
By subdomain (the "domain" mode) - tenant1.example.com, tenant2.example.com
By cookie (the "cookie" mode) - the user selects a tenant through the interface
Tenant configuration
Tenant settings are located in the config/tenants.php file, which includes:
Operating mode (domain/cookie)
Default tenant data
List of additional tenants with their parameters
Each tenant has:
A unique key (used as a subdomain in domain mode)
A name displayed to users
A database name
An API key for API access
Working with tenants
Migrations and data
The application can work in two modes: with a regular database or with a tenant database Standard Laravel commands (migrate, db:seed) use the main database The tenant:db command is used to work with tenant databases
API requests to tenants
When accessing the API, you must specify the X-API-Key header with the value from the configuration The API automatically determines the tenant by the API key and connects to the appropriate database
Twill CMS users
Twill users are created only in the main database
To synchronize users between tenants, use the command:
php artisan tenant:sync-twill-users
Development and debugging
To view the current tenant, use the /debug-tenant route
The X-Current-Tenant header with the current tenant name is added to API responses
In templates, the
tenants variables are available
Creating new tenants
Add tenant information to config/tenants.php
Create a database using the command:
php artisan tenants:setup-databases
Run migrations for the new tenant:
php artisan tenant:db new_tenant --action=migrate --seed
Recommendations
Don't create Twill users in tenants, only in the main database
When developing new features, consider that they should work for all tenants
For local testing in domain mode, add entries to your hosts file
Use the --path parameter to run specific migrations for individual tenants