diff --git a/assets/config.php b/assets/config.php index 00835cc7..99f9b596 100644 --- a/assets/config.php +++ b/assets/config.php @@ -39,7 +39,7 @@ return [ 'cache' => [ 'tag_base' => 'tenant', ], - 'filesystem' => [ // https://stancl-tenancy.netlify.com/docs/filesystem-tenancy/ + 'filesystem' => [ // https://tenancy.samuelstancl.me/docs/filesystem-tenancy/ 'suffix_base' => 'tenant', // Disks which should be suffixed with the suffix_base + tenant id. 'disks' => [ diff --git a/src/Commands/Install.php b/src/Commands/Install.php index 0237473b..39ed31d1 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -74,12 +74,12 @@ Route::get('/', function () { $this->line(''); $this->line("This package lets you store data about tenants either in Redis or in a relational database like MySQL. If you're going to use the database storage, you need to create a tenants table."); - if ($this->confirm('Do you want to publish the default database migration?', true)) { + if ($this->confirm('Do you want to publish the default database migrations?', true)) { $this->callSilent('vendor:publish', [ '--provider' => 'Stancl\Tenancy\TenancyServiceProvider', '--tag' => 'migrations', ]); - $this->info('✔️ Created migration.'); + $this->info('✔️ Created migrations.'); } if (! is_dir(database_path('migrations/tenant'))) { diff --git a/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php b/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php index a2071b83..78d1b2ac 100644 --- a/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php +++ b/src/TenancyBootstrappers/FilesystemTenancyBootstrapper.php @@ -9,8 +9,6 @@ use Illuminate\Support\Facades\Storage; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Tenant; -// todo2 better solution than tenant_asset? - class FilesystemTenancyBootstrapper implements TenancyBootstrapper { protected $originalPaths = []; @@ -24,17 +22,21 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper $this->originalPaths = [ 'disks' => [], 'path' => $this->app->storagePath(), + 'asset' => $this->app['config']['asset_url'], ]; } public function start(Tenant $tenant) { - // todo2 revisit this $suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id; // storage_path() $this->app->useStoragePath($this->originalPaths['path'] . "/{$suffix}"); + // asset() + $this->app['config']['app.asset_url'] = ($this->originalPaths['asset'] ?? $this->app['config']['app.url']) . "/$suffix"; + $this->app['url']->setAssetRoot($this->app['config']['app.asset_url']); + // Storage facade foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { $this->originalPaths['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix(); @@ -54,6 +56,10 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper // storage_path() $this->app->useStoragePath($this->originalPaths['path']); + // asset() + $this->app['config']['app.asset_url'] = $this->originalPaths['asset']; + $this->app['url']->setAssetRoot($this->app['config']['app.asset_url']); + // Storage facade foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { Storage::disk($disk)->getAdapter()->setPathPrefix($this->originalPaths['disks'][$disk]); diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 9ecf22b1..8656df72 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -40,7 +40,12 @@ class TenancyServiceProvider extends ServiceProvider \Stancl\Tenancy\Middleware\InitializeTenancy::class, ]); - $this->app->register(TenantRouteServiceProvider::class); + $this->app->instance('globalUrl', clone $this->app['url']); + $this->app['url']->macro('setAssetRoot', function ($root) { + $this->assetRoot = $root; + + return $this; + }); } /** @@ -79,5 +84,7 @@ class TenancyServiceProvider extends ServiceProvider $this->app->bind('globalCache', function ($app) { return new CacheManager($app); }); + + $this->app->register(TenantRouteServiceProvider::class); } } diff --git a/src/helpers.php b/src/helpers.php index dd492855..54462270 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -33,3 +33,10 @@ if (! \function_exists('tenant_asset')) { return route('stancl.tenancy.asset', ['asset' => $asset]); } } + +if (! \function_exists('global_asset')) { + function global_asset($asset) + { + return app('globalUrl')->asset($asset); + } +}