From a70312cb48ccff0e61873263088bdba0eff9f3aa Mon Sep 17 00:00:00 2001 From: Leandro Guindani Gehlen Date: Fri, 28 Jun 2024 15:10:13 -0300 Subject: [PATCH] Add tenant key resolver to define filesystem path suffix --- src/Bootstrappers/FilesystemTenancyBootstrapper.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Bootstrappers/FilesystemTenancyBootstrapper.php b/src/Bootstrappers/FilesystemTenancyBootstrapper.php index 346892b3..8674df04 100644 --- a/src/Bootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/Bootstrappers/FilesystemTenancyBootstrapper.php @@ -17,6 +17,9 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper /** @var array */ public $originalPaths = []; + /** @var callable */ + protected static $tenantKeyResolver; + public function __construct(Application $app) { $this->app = $app; @@ -33,9 +36,16 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper }); } + public static function resolveTenantKeyUsing(callable $tenantKeyResolver): void + { + static::$tenantKeyResolver = $tenantKeyResolver; + } + public function bootstrap(Tenant $tenant) { - $suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->getTenantKey(); + $tenantKey = static::$tenantKeyResolver ? (static::$tenantKeyResolver)($tenant) : $tenant->getTenantKey(); + + $suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenantKey; // storage_path() if ($this->app['config']['tenancy.filesystem.suffix_storage_path'] ?? true) {