From 01007c3be70a30b35c9cebc8324a68d6479765e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 9 Aug 2019 22:05:43 +0200 Subject: [PATCH] wip --- src/Tenant.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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)]); + } + } +}