mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:54:03 +00:00
finish writing storage driver
This commit is contained in:
parent
fd0712e037
commit
fc76da38cb
2 changed files with 54 additions and 17 deletions
|
|
@ -10,6 +10,58 @@ class Tenant extends Model
|
|||
protected $specialColumns = [];
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Decoded data from the data column.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $dataObject;
|
||||
|
||||
/**
|
||||
* Get data from the data column.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFromData(string $key)
|
||||
{
|
||||
$this->dataObject = $this->dataObject ?? json_decode($this->{$this->dataColumn});
|
||||
return $this->dataObject->$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data from tenant storage.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key)
|
||||
{
|
||||
return $this->$key ?? $this->getFromData($key) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multiple values from tenant storage.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public function getMany(array $keys): array
|
||||
{
|
||||
return array_reduce($keys, function ($keys, $key) {
|
||||
$keys[$key] = $this->get($key);
|
||||
|
||||
return $keys;
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data into tenant storage.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function put(string $key, $value)
|
||||
{
|
||||
if (array_key_exists($key, $this->specialColumns)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue