1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-14 10:04:04 +00:00
This commit is contained in:
Abrar Ahmad 2022-11-22 11:28:27 +05:00
parent c59a514490
commit 90c54ac733

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Cache\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Cache;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
@ -14,10 +15,15 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
protected null|string $originalPrefix = null;
protected string $storeName;
public function __construct(
protected Application $app
) {
}
public function bootstrap(Tenant $tenant): void
{
$this->originalPrefix = config('cache.prefix');
$this->storeName = config('cache.default');
$this->originalPrefix = $this->app['config']['cache.prefix'];
$this->storeName = $this->app['config']['cache.default'];
$this->setCachePrefix('tenant_id_' . $tenant->id);
}
@ -32,20 +38,20 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper
protected function setCachePrefix(string $prefix): void
{
config()->set('cache.prefix', $prefix);
$this->app['config']['cache.prefix'] = $prefix;
app('cache')->forgetDriver($this->storeName);
$this->app['cache']->forgetDriver($this->storeName);
// This is important because the `CacheManager` will have the `$app['config']` array cached
// with old prefixes on the `cache` instance. Simply calling `forgetDriver` only removes
// the `$store` but doesn't update the `$app['config']`.
app()->forgetInstance('cache');
$this->app->forgetInstance('cache');
//This is important because the Cache Repository is using an old version of the CacheManager
app()->forgetInstance('cache.store');
$this->app->forgetInstance('cache.store');
// Forget the cache repository in the container
app()->forgetInstance(Repository::class);
$this->app->forgetInstance(Repository::class);
Cache::clearResolvedInstances();
}