From 8f384ade123aa638a22d4b74bf7db8c84f772d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 19 Jan 2019 23:11:15 +0100 Subject: [PATCH] Fix storage_path() and asset() --- src/Traits/BootstrapsTenancy.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Traits/BootstrapsTenancy.php b/src/Traits/BootstrapsTenancy.php index 8d2eb2fd..57fdc95d 100644 --- a/src/Traits/BootstrapsTenancy.php +++ b/src/Traits/BootstrapsTenancy.php @@ -4,6 +4,8 @@ namespace Stancl\Tenancy; trait BootstrapsTenancy { + public $oldstoragepaths; + public function bootstrap() { $this->switchDatabaseConnection(); @@ -36,11 +38,31 @@ trait BootstrapsTenancy public function suffixFilesystemRootPaths() { + $old = [ + "storage_disks" => [], + "storage_path" => $this->app->storagePath, + "asset" => asset(''), + ]; + $suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . tenant('uuid'); + + // Storage facade foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { + $root = $this->app['config']["filesystems.disks.{$disk}.root"]; + \Storage::disk($disk)->getAdapter()->setPathPrefix( - $this->app['config']["filesystems.disks.{$disk}.root"] . "/{$suffix}" + $root . "/{$suffix}" ); + + $old['storage_disks'][$disk] = $root; } + + // storage_path() + $this->app->useStoragePath($this->app->storagePath() . $path); + + // asset() + $this->app('url')->forceRootUrl(asset('') . $url); + + $this->oldStoragePaths = $old; } }