diff --git a/src/StorageDrivers/DatabaseStorageDriver.php b/src/StorageDrivers/DatabaseStorageDriver.php index d4a20d9a..23ee0a9f 100644 --- a/src/StorageDrivers/DatabaseStorageDriver.php +++ b/src/StorageDrivers/DatabaseStorageDriver.php @@ -10,8 +10,9 @@ class DatabaseStorageDriver implements StorageDriver public $useJson = false; // todo use an instance of tenant model? + // todo write tests verifying that data is decoded and added to the array - public function identifyTenant(string $domain): array + public function identifyTenant(string $domain): array // todo returns data col { $id = $this->getTenantIdByDomain($domain); if (! $id) { @@ -64,7 +65,7 @@ class DatabaseStorageDriver implements StorageDriver public function getMany(string $uuid, array $keys): array { - return Tenant::getMany($keys); + return Tenant::find($uuid)->getMany($keys); } public function put(string $uuid, string $key, $value) diff --git a/src/Tenant.php b/src/Tenant.php index 6405e31a..72bef212 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -77,7 +77,7 @@ class Tenant extends Model $obj = json_decode($this->{$this->dataColumn()}); $obj->$key = $value; - $this->update([$this->getDataColumn() => json_encode($obj)]); + $this->update([$this->dataColumn() => json_encode($obj)]); } return $value; diff --git a/src/TenantManager.php b/src/TenantManager.php index 64fd4a99..ce6cf656 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -203,7 +203,9 @@ final class TenantManager */ public function setTenant(array $tenant): array { - $tenant = $this->jsonDecodeArrayValues($tenant); + if ($this->useJson()) { + $tenant = $this->jsonDecodeArrayValues($tenant); + } $this->tenant = $tenant; diff --git a/tests/TestCase.php b/tests/TestCase.php index 0f360547..90b25129 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -25,7 +25,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase Redis::connection('cache')->flushdb(); config(['database.default' => 'central']); - $this->loadLaravelMigrations(); + $this->loadLaravelMigrations(['--database' => 'central']); $this->loadMigrationsFrom(realpath(__DIR__ . '/../src/assets/migrations')); if ($this->autoCreateTenant) {