From a8523871dbedb0ac56ff794a28708cd82f7e1d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= <33033094+stancl@users.noreply.github.com> Date: Sun, 20 Jan 2019 15:03:11 +0100 Subject: [PATCH 1/4] Add documentation for tenant_asset() --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cbc10a5e..1844354c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,14 @@ ### *A Laravel multi-database tenancy implementation that respects your code.* -You won't have to change a thing in your application's code. +You won't have to change a thing in your application's code.\* - :white_check_mark: No model traits to change database connection - :white_check_mark: No replacing of Laravel classes (`Cache`, `Storage`, ...) with tenancy-aware classes - :white_check_mark: Built-in tenant identification based on hostname +\* depending on how you use the filesystem. Be sure to read [that section](#Filesystem). Everything else will work out of the box. + ## Installation ### Installing the package @@ -356,6 +358,23 @@ The `local` filesystem driver will be suffixed with a directory containing `tena => "/var/www/laravel/multitenancy/storage/app/tenantdbe0b330-1a6e-11e9-b4c3-354da4b4f339/" ``` +`storage_path()` will also be suffixed in the same way. Note that this means that each tenant will have their own storage directory. + +![The folder structure](https://i.imgur.com/GAXQOnN.png) + +If you write to these directories, you will need to create them after you create the tenant. See the docs for [PHP's mkdir](http://php.net/function.mkdir). + +Logs will be saved to `storage/logs` regardless of any changes to `storage_path()`. + +One thing that you **will** have to change if you use storage similarly to the example on the image is your usage of the helper function `asset()` (that is, if you use it). + +You need to make this change to your code: + +```diff +- asset("storage/images/products/$product_id.png"); ++ tenant_asset("images/products/$product_id.png"); +``` + ## Artisan commands ``` From 1fe851a5fa5667943135947a316799fdfbfcc31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= <33033094+stancl@users.noreply.github.com> Date: Sun, 20 Jan 2019 15:05:04 +0100 Subject: [PATCH 2/4] usage -> use --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1844354c..fbf1286f 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ If you write to these directories, you will need to create them after you create Logs will be saved to `storage/logs` regardless of any changes to `storage_path()`. -One thing that you **will** have to change if you use storage similarly to the example on the image is your usage of the helper function `asset()` (that is, if you use it). +One thing that you **will** have to change if you use storage similarly to the example on the image is your use of the helper function `asset()` (that is, if you use it). You need to make this change to your code: From 68cd063ce76f0122cd53ca076495b306fbf5cca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= <33033094+stancl@users.noreply.github.com> Date: Sun, 20 Jan 2019 15:07:13 +0100 Subject: [PATCH 3/4] Remove dd() --- src/Controllers/TenantAssetsController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Controllers/TenantAssetsController.php b/src/Controllers/TenantAssetsController.php index 8f2aa6a4..a5db2fea 100644 --- a/src/Controllers/TenantAssetsController.php +++ b/src/Controllers/TenantAssetsController.php @@ -16,7 +16,6 @@ class TenantAssetController extends Controller try { return response()->file(storage_path('app/public/' . $path)); } catch (\Throwable $th) { - dd(storage_path('app/public/' . $path)); abort(404); } } From a6544d6056d8cb9e0abcbbe343c092ad36201a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= <33033094+stancl@users.noreply.github.com> Date: Sun, 20 Jan 2019 15:10:50 +0100 Subject: [PATCH 4/4] Rename Filesystem section to avoid a name conflicts --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbf1286f..6de85210 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ You won't have to change a thing in your application's code.\* - :white_check_mark: No replacing of Laravel classes (`Cache`, `Storage`, ...) with tenancy-aware classes - :white_check_mark: Built-in tenant identification based on hostname -\* depending on how you use the filesystem. Be sure to read [that section](#Filesystem). Everything else will work out of the box. +\* depending on how you use the filesystem. Be sure to read [that section](#filesystemstorage). Everything else will work out of the box. ## Installation @@ -142,7 +142,7 @@ config('tenancy.filesystem.suffix_base') . $uuid These changes will only apply for disks listen in `disks`. -You can see an example in the [Filesystem](#Filesystem) section of the documentation. +You can see an example in the [Filesystem](#filesystemstorage) section of the documentation. # Usage @@ -329,7 +329,7 @@ Connections listed in the `tenancy.redis.prefixed_connections` config array use Both `cache()` and `Cache` will use `Stancl\Tenancy\CacheManager`, which adds a tag (`prefix_base` + tenant UUID) to all methods called on it. -## Filesystem +## Filesystem/Storage Assuming the following tenancy config: