# Stancl Tenancy integration notes

The central database stores tenant metadata and custom domains. Each school receives its own MySQL database. Never select a tenant database using a request parameter or an untrusted `tenant_id`.

## Provider registration
For Laravel 11, register `Stancl\Tenancy\TenancyServiceProvider::class` in `bootstrap/providers.php` if it is not auto-discovered. Confirm the package's installed version and generated provider instructions.

## Tenant routes
Use `routes/tenant.php` with `InitializeTenancyByDomain` and `PreventAccessFromCentralDomains`. In `bootstrap/app.php`, append the tenant route file through Laravel routing configuration, or use the route registration pattern recommended by the exact installed Stancl Tenancy v3 release. Avoid loading the same web routes twice.

## Database provisioning
The MySQL database manager needs permission to create and drop databases. Some reseller-hosting accounts restrict database creation to databases created manually in the control panel. Confirm with 20i whether the reseller package permits the required database-per-tenant operation and database naming limits before choosing this architecture.

If automatic database creation is not permitted, use a central database with a mandatory `tenant_id` column and global scopes/policies, or manually provision each tenant database in the hosting control panel and configure the tenancy database manager accordingly. Do not silently assume the host grants CREATE DATABASE.

## Migration path
Configure Stancl's tenant migration path to `database/migrations/tenant` in the installed package's tenancy migration configuration/command. Run tenant migrations only after a tenant database exists. Keep central migrations separate from tenant migrations.
