|LazyCollection $tenants */ public function __invoke(Tenant|Collection|LazyCollection $tenants): void { $tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants; /** @var Tenant $tenant */ foreach ($tenants as $tenant) { foreach ($this->possibleTenantSymlinks($tenant) as $publicPath => $storagePath) { $this->removeLink($publicPath, $tenant); } } } protected function removeLink(string $publicPath, Tenant $tenant): void { if (! $this->symlinkExists($publicPath)) { return; } $files = app()->make('files'); event(new RemovingStorageSymlink($tenant)); $files->delete($publicPath); event(new StorageSymlinkRemoved($tenant)); if (! static::$removeNestedDirectories) { return; } $publicRoot = realpath(public_path()); $directory = realpath(dirname($publicPath)); if ($publicRoot === false || $directory === false) { return; } // Remove the directories CreateStorageSymlinksAction created for the symlink // until a non-empty one is reached. while (str_starts_with(rtrim($directory, '/\\'), rtrim($publicRoot, '/\\') . DIRECTORY_SEPARATOR) && $files->isEmptyDirectory($directory)) { if (! @rmdir($directory)) { // Stop the loop if the directory couldn't be removed break; } $directory = dirname($directory); } } }