diff --git a/src/Listeners/CreateTenantStorage.php b/src/Listeners/CreateTenantStorage.php new file mode 100644 index 00000000..3210a050 --- /dev/null +++ b/src/Listeners/CreateTenantStorage.php @@ -0,0 +1,24 @@ +run($event->tenant, fn () => storage_path()); + $cache_path = "$storage_path/framework/cache"; + + if (! is_dir($cache_path)) { + // Create the tenant's storage directory and /framework/cache within (used for e.g. real-time facades) + mkdir($cache_path, 0750, true); + } + } +} diff --git a/src/Listeners/DeleteTenantStorage.php b/src/Listeners/DeleteTenantStorage.php new file mode 100644 index 00000000..c32e14ba --- /dev/null +++ b/src/Listeners/DeleteTenantStorage.php @@ -0,0 +1,32 @@ +central(fn () => storage_path()); + $path = tenancy()->run($event->tenant, fn () => storage_path()); + + // Skip storage deletion if tenant's storage path is the same as central storage path + $tenantPathIsCentral = realpath($path) === realpath($centralPath); + + if (is_dir($path) && ! $tenantPathIsCentral) { + File::deleteDirectory($path); + } + } +}