From 6cb9deb08e1dfc875dce72243662b5db91659cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 28 Jan 2020 17:03:25 +0100 Subject: [PATCH 1/6] replace ->tenant access with ->getTenant() calls --- docs/source/v2/custom-db-connections.blade.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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')]); }); ``` From cb497f9404226e97d124242f28e1147430313807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 10 Mar 2020 23:04:02 +0100 Subject: [PATCH 2/6] Update donation link --- dist/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ From cffbb8d1cb0242ed32db5d19f65d3bc5670dfb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sun, 15 Mar 2020 20:12:10 +0100 Subject: [PATCH 3/6] Mention creating a public disk to improve performance --- docs/source/v2/filesystem-tenancy.blade.md | 6 ++++++ 1 file changed, 6 insertions(+) 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. From b2124349906c99761c5695701c9a90e0877f6b54 Mon Sep 17 00:00:00 2001 From: Nick Parker Date: Sun, 15 Mar 2020 16:32:11 -0400 Subject: [PATCH 4/6] Provide exempt_domains examples (#44) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Provide exempt_domains example When I was setting this up, I noticed that using the https protocol would cause the package to throw an exception. After a bit of tinkering, I realized that the domain needs to be completely stripped (no protocol) in order for the central app to recognize it. This PR just adds a simple example to the docs for this. * Update central-app.blade.md * Update central-app.blade.md * Update docs/source/v2/central-app.blade.md Co-Authored-By: Samuel Štancl * Update docs/source/v2/configuration.blade.md * ` instead of ``` * ` instead of ``` Co-authored-by: Samuel Štancl --- docs/source/v2/central-app.blade.md | 2 ++ docs/source/v2/configuration.blade.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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} From 3d2892386417f90a41d60168945a8a3ce3162d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 17 Mar 2020 19:29:01 +0100 Subject: [PATCH 5/6] Mention tenancy initialization by request data --- .../v2/middleware-configuration.blade.md | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/source/v2/middleware-configuration.blade.md b/docs/source/v2/middleware-configuration.blade.md index 09a695a..2f810ea 100644 --- a/docs/source/v2/middleware-configuration.blade.md +++ b/docs/source/v2/middleware-configuration.blade.md @@ -7,6 +7,32 @@ 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 @@ -17,4 +43,4 @@ $this->app->bind(InitializeTenancy::class, function ($app) { // return redirect()->route('foo'); }); }); -``` \ No newline at end of file +``` From eba282a0fe3167c4c57d700a505c317d26c3dde9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 6 Apr 2020 15:16:39 +0200 Subject: [PATCH 6/6] onFail accepts $request and $next --- docs/source/v2/middleware-configuration.blade.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/v2/middleware-configuration.blade.md b/docs/source/v2/middleware-configuration.blade.md index 2f810ea..7320a11 100644 --- a/docs/source/v2/middleware-configuration.blade.md +++ b/docs/source/v2/middleware-configuration.blade.md @@ -39,7 +39,7 @@ When a tenant route is visited and the tenant can't be identified, an exception // 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'); }); });