1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 02:14:03 +00:00
This commit is contained in:
Samuel Štancl 2019-08-09 22:05:43 +02:00
parent bee7f34973
commit 01007c3be7

View file

@ -6,5 +6,20 @@ use Illuminate\Database\Eloquent\Model;
class Tenant extends Model class Tenant extends Model
{ {
// todo if not attribute exists in db, put into json data 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)]);
}
}
} }