1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 13:34:04 +00:00
This commit is contained in:
Samuel Štancl 2019-08-09 22:50:46 +02:00
commit fd0712e037
2 changed files with 16 additions and 27 deletions

View file

@ -6,20 +6,21 @@ use Illuminate\Database\Eloquent\Model;
class Tenant extends Model
{
public function getDataColumn()
{
return 'data';
}
protected $dataColumn = 'data';
protected $specialColumns = [];
protected $guarded = [];
public function put(string $key, $value)
{
if ($this->getConnection()->getSchemaBuilder()->hasColumn($this->getTable(), $key)) {
if (array_key_exists($key, $this->specialColumns)) {
$this->update([$key => $value]);
} else {
$obj = json_decode($this->{$this->getDataColumn()});
$obj = json_decode($this->{$this->dataColumn});
$obj->$key = $value;
$this->update([$this->getDataColumn() => json_encode($obj)]);
}
return $value;
}
}