diff --git a/dist/index.html b/dist/index.html index fbcc107..88795d9 100644 --- a/dist/index.html +++ b/dist/index.html @@ -45,7 +45,7 @@
diff --git a/docs/source/v2/central-app.blade.md b/docs/source/v2/central-app.blade.md index 6555505..9aeee9f 100644 --- a/docs/source/v2/central-app.blade.md +++ b/docs/source/v2/central-app.blade.md @@ -17,6 +17,8 @@ Routes in the `routes/web.php` file are the central routes. When they are visite However, since you don't want routes related to the app on your main domain and sign up forms on tenant domains, you must also define what domains host the central stuff in the `tenancy.exempt_domains` config. +The exempt domains should not include the protocol. For example, you should include `example.com` rather than `https://example.com`. + ## Using central things inside the tenant app {#using-central-things-inside-the-tenant-app} To use central things (databases/caches/Redis connections/filesystems/...) on special places of your tenant app, you may do the following. diff --git a/docs/source/v2/configuration.blade.md b/docs/source/v2/configuration.blade.md index 2b48df3..e836f8a 100644 --- a/docs/source/v2/configuration.blade.md +++ b/docs/source/v2/configuration.blade.md @@ -38,7 +38,7 @@ Controller namespace used for routes in `routes/tenant.php`. The default value i ### `exempt_domains` {#exempt-domains} -If a hostname from this array is visited, the `tenant.php` routes won't be registered, letting you use the same routes as in that file. +If a hostname from this array is visited, the `tenant.php` routes won't be registered, letting you use the same routes as in that file. This should be the domain without the protocol (i.e., `example.com` rather than `https://example.com`). ### `database` {#database} diff --git a/docs/source/v2/custom-db-connections.blade.md b/docs/source/v2/custom-db-connections.blade.md index dade6d9..e93196a 100644 --- a/docs/source/v2/custom-db-connections.blade.md +++ b/docs/source/v2/custom-db-connections.blade.md @@ -19,8 +19,8 @@ Tenant::new()->withData([ // Make tweaks to the connection before bootstrapping tenancy tenancy()->hook('bootstrapping', function ($tenantManager) { - config(['database.connections.someTenantConnectionTemplate.name' => $tenantManager->tenant['database_name']]); - config(['database.connections.someTenantConnectionTemplate.password' => $tenantManager->tenant['database_password']]); - config(['database.connections.someTenantConnectionTemplate.host' => $tenantManager->tenant['database_host']]); + config(['database.connections.someTenantConnectionTemplate.name' => $tenantManager->getTenant('database_name')]); + config(['database.connections.someTenantConnectionTemplate.password' => $tenantManager->getTenant('database_password')]); + config(['database.connections.someTenantConnectionTemplate.host' => $tenantManager->getTenant('database_host')]); }); ``` diff --git a/docs/source/v2/filesystem-tenancy.blade.md b/docs/source/v2/filesystem-tenancy.blade.md index 78af302..59721fa 100644 --- a/docs/source/v2/filesystem-tenancy.blade.md +++ b/docs/source/v2/filesystem-tenancy.blade.md @@ -60,4 +60,10 @@ Storage::disk('public')->put($filename, $data); Storage::disk('local')->put("public/$filename", $data); ``` +Note that every request for a tenant asset requires a full framework boot and tenancy initialization. This is not ideal if you have some assets that occur on each page (like logos). So for non-private assets, you may want to create a disk and use URLs from that disk instead. For example: + +```php +Storage::disk('app-public')->url('tenants/logos/' . tenant()->id . '.png'); +``` + If you want to store something globally, simply create a new disk and *don't* add it to the `tenancy.filesystem.disks` config. diff --git a/docs/source/v2/middleware-configuration.blade.md b/docs/source/v2/middleware-configuration.blade.md index 09a695a..7320a11 100644 --- a/docs/source/v2/middleware-configuration.blade.md +++ b/docs/source/v2/middleware-configuration.blade.md @@ -7,14 +7,40 @@ section: content # Middleware Configuration {#middleware-configuration} +## Header or query parameter based identification {#header-or-query-parameter-based-identification} + +To identify tenants using request headers or query parameters, you may use the `InitializeTenancyByRequestData` middleware. + +Create a **central** route (don't apply the `tenancy` middleware group on it and don't put it into `routes/tenant.php`) and apply this middleware on the route: + +```php +\Stancl\Tenancy\Middleware\InitializeTenancyByRequestData::class +``` + +To customize the header, query parameter, and `onFail` logic, you may do this in your `AppServiceProvider::boot()`: + +```php +// use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData::class; + +$this->app->bind(InitializeTenancyByRequestData::class, function ($app) { + return new InitializeTenancyByRequestData('header name', 'query parameter', function ($exception) { + // return redirect()->route('foo'); + }); +}); +``` + +To disable identification using header or query parameter, set the respective parameter to `null`. + +## Customizing the onFail logic {#customizing-the-onfail-logic} + When a tenant route is visited and the tenant can't be identified, an exception is thrown. If you want to change this behavior, to a redirect for example, add this to your `app/Providers/AppServiceProvider.php`'s `boot()` method: ```php // use Stancl\Tenancy\Middleware\InitializeTenancy; $this->app->bind(InitializeTenancy::class, function ($app) { - return new InitializeTenancy(function ($exception) { + return new InitializeTenancy(function ($exception, $request, $next) { // return redirect()->route('foo'); }); }); -``` \ No newline at end of file +```