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

Integrate into Laravel

Configuring Laravel to become multi tenant.

Service provider

The hyn packages are created to make it as easy as possible for you. Most functionality is added dynamically by hooking into the Laravel ecosystem. This unobtrusive behavior is initiated by registering the main service provider. Add the following under your providers array in config/app.php.

/*
 * Hyn tenancy providers
 */
Hyn\Tenancy\Providers\TenancyProvider::class,
Hyn\Tenancy\Providers\WebserverProvider::class,

🚧

Register the WebserverProvider only if you intend to use the native integration into Apache, Nginx or any other webserver configuration. The recommendation is to leave this entry out on existing environments.

Third party eloquent models (optional)

To support multi tenancy in other packages and your own code, you'll have to make sure the eloquent models of this code uses the connection meant for the tenant or the system. In order to have all code use the tenant connection by default update the aliases array in your app/config.php by replacing the alias for Eloquent.

'Eloquent'  => Hyn\Tenancy\Abstracts\TenantModel::class,

If instead you'd like to have all Eloquent models use the system connection by default just set the alias to the SystemModel.

'Eloquent'  => Hyn\Tenancy\Abstracts\SystemModel::class,

❗️

Changing the alias while your application has several models in place, might have a serious impact. Please be aware that modifying the alias will result in all extended Models changing their connection too. Advice: on a new application pick one and stick to it, on an existing application keep the old alias and refactor your old Models to extend one of the abstract Models provided.