1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 13:34:04 +00:00

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.
This commit is contained in:
lukinovec 2026-08-08 14:22:29 +02:00 committed by Samuel Stancl
parent 179114bfb7
commit 98d86478e7

View file

@ -7,15 +7,21 @@ namespace Stancl\Tenancy\Concerns;
use Exception; use Exception;
use Stancl\Tenancy\Contracts\Tenant; 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 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. * 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. * 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 * The same disk root can be symlinked to multiple public paths, which is why the public path
* is the Collection key. * is the array key.
* *
* @return array<string, string> * @return array<string, string>
*/ */
@ -26,7 +32,7 @@ trait DealsWithTenantSymlinks
$rootOverrides = config('tenancy.filesystem.root_override'); $rootOverrides = config('tenancy.filesystem.root_override');
$tenantKey = $tenant->getTenantKey(); $tenantKey = $tenant->getTenantKey();
$tenantStoragePath = tenancy()->run($tenant, fn () => storage_path()); $tenantDisks = tenancy()->run($tenant, fn () => config('filesystems.disks'));
/** @var array<string, string> $symlinks */ /** @var array<string, string> $symlinks */
$symlinks = []; $symlinks = [];
@ -45,9 +51,8 @@ trait DealsWithTenantSymlinks
} }
$publicPath = str_replace('%tenant%', (string) $tenantKey, $publicPath); $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; return $symlinks;