Unable to use package in tenancy mode #257
Replies: 4 comments
-
Converted to a discussion since nothing is broken in the package. I myself don't use Tenancy, so no idea how to solve this. I think there's another discussion here somewhere with some hints to an implementation. |
Beta Was this translation helpful? Give feedback.
-
I have literally spent two days to find a solution for this, if you find my answer helpful feel free to buy me a coffee at PayPal using this address iknowbrain@gmail.com. And then within your settings class, you can override the method repository() to return correct repository accordingly. For example in my case, I created a Of course, don't forget to change the |
Beta Was this translation helpful? Give feedback.
-
I'm having a weird problem when using the I'm wondering if you guys are using |
Beta Was this translation helpful? Give feedback.
-
Thought I'd just throw this in here because it works perfectly for me. I use a custom repository: class SettingsRepository extends DatabaseSettingsRepository
{
public function __construct(array $config)
{
parent::__construct($config);
Assert::notNull(tenant());
}
public function updatePropertiesPayload(string $group, array $properties): void
{
$propertiesInBatch = collect($properties)->map(function ($payload, $name) use ($group) {
return [
'group' => $group,
'name' => $name,
'payload' => $this->encode($payload),
'tenant_id' => tenant()->getTenantKey()
];
})->values()->toArray();
$this->getBuilder()
->where('group', $group)
->upsert($propertiesInBatch, ['group', 'name', 'tenant_id'], ['payload']);
}
} Then I modified the settings table migration to have a tenant_id: Schema::create('settings', function (Blueprint $table): void {
$table->id();
$table->string('tenant_id');
$table->string('group');
$table->string('name');
$table->boolean('locked')->default(false);
$table->json('payload');
$table->timestamps();
$table->unique(['group', 'name', 'tenant_id']);
}); Then a custom model: class SpatieSettings extends SettingsProperty
{
use BelongsToTenant;
} Then when you create a setting migration, place it in the tenant migration folder and run With this setup, you can just use the package like normal and it'll pull per tenant. |
Beta Was this translation helpful? Give feedback.
-
hi guys... i'm using this wonderfull package with spatie settings, but it always try to load settings from central datasse, i create a new model class that extend spatie settings model:
But i get: Database connection [tenant] not configured
Can someone help me please?
Beta Was this translation helpful? Give feedback.
All reactions