diff --git a/src/Tenant.php b/src/Tenant.php index 364e812f..aa2d806e 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -6,5 +6,20 @@ use Illuminate\Database\Eloquent\Model; class Tenant extends Model { - // todo if not attribute exists in db, put into json data -} \ No newline at end of file + public function getDataColumn() + { + return 'data'; + } + + public function put(string $key, $value) + { + if ($this->getConnection()->getSchemaBuilder()->hasColumn($this->getTable(), $key)) { + $this->update([$key => $value]); + } else { + $obj = json_decode($this->{$this->getDataColumn()}); + $obj->$key = $value; + + $this->update([$this->getDataColumn() => json_encode($obj)]); + } + } +}