From 98d86478e756a722e70b805e6597ea28e73bcc54 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sat, 8 Aug 2026 14:22:29 +0200 Subject: [PATCH] Make storage symlinks point to the tenant's disk root instead of storage_path() possibleTenantSymlinks() resolved the root_override template on its own, using storage_path() for %storage_path% and leaving %original_storage_path% and %tenant% unreplaced. Let the FS bootstrapper resolve the placeholders tenant instead, so the symlinks point where the disks actually write. --- src/Concerns/DealsWithTenantSymlinks.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Concerns/DealsWithTenantSymlinks.php b/src/Concerns/DealsWithTenantSymlinks.php index 114eadb5..479db163 100644 --- a/src/Concerns/DealsWithTenantSymlinks.php +++ b/src/Concerns/DealsWithTenantSymlinks.php @@ -7,15 +7,21 @@ namespace Stancl\Tenancy\Concerns; use Exception; use Stancl\Tenancy\Contracts\Tenant; +/** + * Requires FilesystemTenancyBootstrapper to be enabled, since the tenant symlinks + * point to the disk roots scoped by the bootstrapper. + * + * @see \Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper + */ trait DealsWithTenantSymlinks { /** - * Get all possible tenant symlinks, existing or not (array of ['public path' => 'storage path']). + * Get all possible tenant symlinks, existing or not (array of ['public path' => 'disk root']). * * Tenants can have a symlink for each disk registered in the tenancy.filesystem.url_override config. * This is used for creating all possible tenant symlinks and removing all existing tenant symlinks. - * The same storage path can be symlinked to multiple public paths, which is why the public path - * is the Collection key. + * The same disk root can be symlinked to multiple public paths, which is why the public path + * is the array key. * * @return array */ @@ -26,7 +32,7 @@ trait DealsWithTenantSymlinks $rootOverrides = config('tenancy.filesystem.root_override'); $tenantKey = $tenant->getTenantKey(); - $tenantStoragePath = tenancy()->run($tenant, fn () => storage_path()); + $tenantDisks = tenancy()->run($tenant, fn () => config('filesystems.disks')); /** @var array $symlinks */ $symlinks = []; @@ -45,9 +51,8 @@ trait DealsWithTenantSymlinks } $publicPath = str_replace('%tenant%', (string) $tenantKey, $publicPath); - $storagePath = str_replace('%storage_path%', $tenantStoragePath, $rootOverrides[$disk]); - $symlinks[public_path($publicPath)] = $storagePath; + $symlinks[public_path($publicPath)] = $tenantDisks[$disk]['root']; } return $symlinks;