Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v9 is loading config file from disk #1867

Open
razvan-p opened this issue Jan 8, 2025 · 0 comments
Open

v9 is loading config file from disk #1867

razvan-p opened this issue Jan 8, 2025 · 0 comments

Comments

@razvan-p
Copy link

razvan-p commented Jan 8, 2025

Hi! We have a multitenancy app which runs a backup every day. After updating from v8 to v9 we remarked that config is always loaded from config.php file from disk. This way we can't configure dynamically the config options according to each tenant. This is our code for changing the config dynamically which is working in v8, but not in v9:

<?php

namespace App\Tasks;

use Spatie\Multitenancy\Contracts\IsTenant;
use Spatie\Multitenancy\Tasks\SwitchTenantTask;

class SwitchBackupDatabaseTask implements SwitchTenantTask
{
    public function __construct(protected ?array $originalBackupDatabase = null, protected ?string $originalBackupFilenamePrefix = null)
    {
        $this->originalBackupDatabase ??= config('backup.backup.source.databases');
        $this->originalBackupFilenamePrefix ??= config('backup.backup.destination.filename_prefix');
    }

    public function makeCurrent(IsTenant $tenant): void
    {
        config()->set('backup.backup.source.databases', ['tenant']);
        config()->set('backup.backup.destination.filename_prefix', $tenant->database . '-');
    }

    public function forgetCurrent(): void
    {
        config()->set('backup.backup.source.databases', $this->originalBackupDatabase);
        config()->set('backup.backup.destination.filename_prefix', $this->originalBackupFilenamePrefix);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant