These docs are for v1.0. Click to read the latest docs for v5.

Tenant identification

Explanation of how the tenancy package identifies the tenant.

1. Service provider registration

Hyn multi tenancy hooks itself into the Laravel ecosystem using the hyn/framework package. This package has a FrameworkServiceProvider that identifies whether other hyn packages are installed and register those service providers accordingly.

In a default situation only a few packages exist:

  • hyn/framework
  • hyn/multi-tenant
  • hyn/webserver

Of these three the service providers will be automatically registered and booted when needed.

2. Redirect middleware (optional)

The hostname allows some specific configurations to be set. Amongst others that redirection to another hostname occurs. In order for this redirection to work the middleware HostnameMiddleware of the multi-tenant package is added to all routes on runtime.

📘

Configurable

You can disable this middleware from the multi-tenant configuration file.

3. Service providers booting

Most of the magic happens when the service providers boot, especially the MultiTenantServiceProvider handles the majority of the runtime configuration for tenancy:

  • Identify what the hostname is of the request (ignores artisan for instance).
  • Query the system database for any matching hostnames.
  • Load necessary related information of this hostname, including the website details.
  • If for this website a storage folder exists, sets up each additional piece of code, like routes etc.
  • Also set up the database connection "tenant" to allow connecting to the tenant database.