diff --git a/assets/config.php b/assets/config.php index e003d1c8..50b53b0f 100644 --- a/assets/config.php +++ b/assets/config.php @@ -248,20 +248,19 @@ return [ /* * Tenant-aware Storage::disk()->url() can be enabled for specific local disks here - * by mapping the disk's name to a name with '%tenant_id%' (this will be used as the public name of the disk). + * by mapping the disk's name to a name with '%tenant%' (this will be used as the public name of the disk). * Doing that will override the disk's default URL with a URL containing the current tenant's key. * * For example, Storage::disk('public')->url('') will return https://your-app.test/storage/ by default. - * After adding 'public' => 'public-%tenant_id%' to 'url_override', - * the returned URL will be https://your-app.test/public-1/ (%tenant_id% gets substitued by the current tenant's ID). + * After adding 'public' => 'public-%tenant%' to 'url_override', + * the returned URL will be https://your-app.test/public-1/ (%tenant% gets substitued by the current tenant's key). * * Use `php artisan tenants:link` to create a symbolic link from the tenant's storage to its public directory. */ 'url_override' => [ // Note that the local disk you add must exist in the tenancy.filesystem.root_override config - // todo@v4 Rename %tenant_id% to %tenant_key% // todo@v4 Rename url_override to something that describes the config key better - 'public' => 'public-%tenant_id%', + 'public' => 'public-%tenant%', ], /** diff --git a/src/Bootstrappers/FilesystemTenancyBootstrapper.php b/src/Bootstrappers/FilesystemTenancyBootstrapper.php index b64ff9ed..67914740 100644 --- a/src/Bootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/Bootstrappers/FilesystemTenancyBootstrapper.php @@ -83,7 +83,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper $this->originalPaths['disks']['url'][$disk] = $diskConfig['url'] ?? null; if ($url = str_replace( - '%tenant_id%', + '%tenant%', (string) $tenant->getTenantKey(), $this->app['config']["tenancy.filesystem.url_override.{$disk}"] ?? '' )) { diff --git a/src/Concerns/DealsWithTenantSymlinks.php b/src/Concerns/DealsWithTenantSymlinks.php index c59928bc..bc908b22 100644 --- a/src/Concerns/DealsWithTenantSymlinks.php +++ b/src/Concerns/DealsWithTenantSymlinks.php @@ -30,7 +30,7 @@ trait DealsWithTenantSymlinks foreach ($diskUrls as $disk => $publicPath) { $storagePath = str_replace('%storage_path%', $suffixBase . $tenantKey, $disks[$disk]); - $publicPath = str_replace('%tenant_id%', (string) $tenantKey, $publicPath); + $publicPath = str_replace('%tenant%', (string) $tenantKey, $publicPath); tenancy()->central(function () use ($symlinks, $publicPath, $storagePath) { $symlinks->push([public_path($publicPath) => storage_path($storagePath)]); diff --git a/tests/ActionTest.php b/tests/ActionTest.php index c9de07d8..e1727c94 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -26,7 +26,7 @@ test('create storage symlinks action works', function() { ], 'tenancy.filesystem.suffix_base' => 'tenant-', 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); /** @var Tenant $tenant */ @@ -50,7 +50,7 @@ test('remove storage symlinks action works', function() { ], 'tenancy.filesystem.suffix_base' => 'tenant-', 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); /** @var Tenant $tenant */ diff --git a/tests/BootstrapperTest.php b/tests/BootstrapperTest.php index 588ca017..77e14349 100644 --- a/tests/BootstrapperTest.php +++ b/tests/BootstrapperTest.php @@ -233,7 +233,7 @@ test('tenant storage can get deleted after the tenant when DeletingTenant listen FilesystemTenancyBootstrapper::class, ], 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); $tenant1 = Tenant::create(); @@ -276,7 +276,7 @@ test('files can get fetched using the storage url', function() { FilesystemTenancyBootstrapper::class, ], 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); $tenant1 = Tenant::create(); @@ -289,7 +289,7 @@ test('files can get fetched using the storage url', function() { Storage::disk('public')->put($tenantFileName = 'tenant1.txt', $tenantKey = $tenant1->getTenantKey()); $url = Storage::disk('public')->url($tenantFileName); - $tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant_id%', $tenantKey); + $tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant%', $tenantKey); $hostname = Str::of($url)->before($tenantDiskName); $parsedUrl = Str::of($url)->after($hostname); @@ -300,7 +300,7 @@ test('files can get fetched using the storage url', function() { Storage::disk('public')->put($tenantFileName = 'tenant2.txt', $tenantKey = $tenant2->getTenantKey()); $url = Storage::disk('public')->url($tenantFileName); - $tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant_id%', $tenantKey); + $tenantDiskName = Str::of(config('tenancy.filesystem.url_override.public'))->replace('%tenant%', $tenantKey); $hostname = Str::of($url)->before($tenantDiskName); $parsedUrl = Str::of($url)->after($hostname); @@ -337,7 +337,7 @@ test('create and delete storage symlinks jobs work', function() { ], 'tenancy.filesystem.suffix_base' => 'tenant-', 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); /** @var Tenant $tenant */ diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index e5da16b7..02a9c948 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -41,7 +41,7 @@ beforeEach(function () { ], 'tenancy.filesystem.suffix_base' => 'tenant-', 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', - 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + 'tenancy.filesystem.url_override.public' => 'public-%tenant%' ]); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);