mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
asset() tenancy
This commit is contained in:
parent
cf71fa5979
commit
6134c8113b
5 changed files with 27 additions and 7 deletions
|
|
@ -39,7 +39,7 @@ return [
|
||||||
'cache' => [
|
'cache' => [
|
||||||
'tag_base' => 'tenant',
|
'tag_base' => 'tenant',
|
||||||
],
|
],
|
||||||
'filesystem' => [ // https://stancl-tenancy.netlify.com/docs/filesystem-tenancy/
|
'filesystem' => [ // https://tenancy.samuelstancl.me/docs/filesystem-tenancy/
|
||||||
'suffix_base' => 'tenant',
|
'suffix_base' => 'tenant',
|
||||||
// Disks which should be suffixed with the suffix_base + tenant id.
|
// Disks which should be suffixed with the suffix_base + tenant id.
|
||||||
'disks' => [
|
'disks' => [
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,12 @@ Route::get('/', function () {
|
||||||
|
|
||||||
$this->line('');
|
$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.");
|
$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', [
|
$this->callSilent('vendor:publish', [
|
||||||
'--provider' => 'Stancl\Tenancy\TenancyServiceProvider',
|
'--provider' => 'Stancl\Tenancy\TenancyServiceProvider',
|
||||||
'--tag' => 'migrations',
|
'--tag' => 'migrations',
|
||||||
]);
|
]);
|
||||||
$this->info('✔️ Created migration.');
|
$this->info('✔️ Created migrations.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_dir(database_path('migrations/tenant'))) {
|
if (! is_dir(database_path('migrations/tenant'))) {
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ use Illuminate\Support\Facades\Storage;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
// todo2 better solution than tenant_asset?
|
|
||||||
|
|
||||||
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
protected $originalPaths = [];
|
protected $originalPaths = [];
|
||||||
|
|
@ -24,17 +22,21 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
$this->originalPaths = [
|
$this->originalPaths = [
|
||||||
'disks' => [],
|
'disks' => [],
|
||||||
'path' => $this->app->storagePath(),
|
'path' => $this->app->storagePath(),
|
||||||
|
'asset' => $this->app['config']['asset_url'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start(Tenant $tenant)
|
public function start(Tenant $tenant)
|
||||||
{
|
{
|
||||||
// todo2 revisit this
|
|
||||||
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
|
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
|
||||||
|
|
||||||
// storage_path()
|
// storage_path()
|
||||||
$this->app->useStoragePath($this->originalPaths['path'] . "/{$suffix}");
|
$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
|
// Storage facade
|
||||||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||||
$this->originalPaths['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix();
|
$this->originalPaths['disks'][$disk] = Storage::disk($disk)->getAdapter()->getPathPrefix();
|
||||||
|
|
@ -54,6 +56,10 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
// storage_path()
|
// storage_path()
|
||||||
$this->app->useStoragePath($this->originalPaths['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
|
// Storage facade
|
||||||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||||
Storage::disk($disk)->getAdapter()->setPathPrefix($this->originalPaths['disks'][$disk]);
|
Storage::disk($disk)->getAdapter()->setPathPrefix($this->originalPaths['disks'][$disk]);
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,12 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
\Stancl\Tenancy\Middleware\InitializeTenancy::class,
|
\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) {
|
$this->app->bind('globalCache', function ($app) {
|
||||||
return new CacheManager($app);
|
return new CacheManager($app);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->register(TenantRouteServiceProvider::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,10 @@ if (! \function_exists('tenant_asset')) {
|
||||||
return route('stancl.tenancy.asset', ['asset' => $asset]);
|
return route('stancl.tenancy.asset', ['asset' => $asset]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! \function_exists('global_asset')) {
|
||||||
|
function global_asset($asset)
|
||||||
|
{
|
||||||
|
return app('globalUrl')->asset($asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue