mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 11:54:03 +00:00
make getCustomColumns() and getDataColumn() static again
This commit is contained in:
parent
72de33a3d4
commit
89e00fbcd9
2 changed files with 13 additions and 13 deletions
|
|
@ -42,7 +42,7 @@ trait VirtualColumn
|
||||||
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
|
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($this->getAttribute($this->getDataColumn()) ?? [] as $key => $value) {
|
foreach ($this->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
|
||||||
$attributeHasEncryptedCastable = in_array(data_get($this->getCasts(), $key), $encryptedCastables);
|
$attributeHasEncryptedCastable = in_array(data_get($this->getCasts(), $key), $encryptedCastables);
|
||||||
|
|
||||||
if ($attributeHasEncryptedCastable && $this->valueEncrypted($value)) {
|
if ($attributeHasEncryptedCastable && $this->valueEncrypted($value)) {
|
||||||
|
|
@ -54,7 +54,7 @@ trait VirtualColumn
|
||||||
$this->syncOriginalAttribute($key);
|
$this->syncOriginalAttribute($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAttribute($this->getDataColumn(), null);
|
$this->setAttribute(static::getDataColumn(), null);
|
||||||
|
|
||||||
$this->dataEncoded = false;
|
$this->dataEncoded = false;
|
||||||
}
|
}
|
||||||
|
|
@ -65,8 +65,8 @@ trait VirtualColumn
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataColumn = $this->getDataColumn();
|
$dataColumn = static::getDataColumn();
|
||||||
$customColumns = $this->getCustomColumns();
|
$customColumns = static::getCustomColumns();
|
||||||
$attributes = array_filter($this->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
|
$attributes = array_filter($this->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
|
||||||
|
|
||||||
// Remove data column from the attributes
|
// Remove data column from the attributes
|
||||||
|
|
@ -166,19 +166,19 @@ trait VirtualColumn
|
||||||
public function getCasts()
|
public function getCasts()
|
||||||
{
|
{
|
||||||
return array_merge(parent::getCasts(), [
|
return array_merge(parent::getCasts(), [
|
||||||
$this->getDataColumn() => 'array',
|
static::getDataColumn() => 'array',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the column that stores additional data.
|
* Get the name of the column that stores additional data.
|
||||||
*/
|
*/
|
||||||
public function getDataColumn(): string
|
public static function getDataColumn(): string
|
||||||
{
|
{
|
||||||
return 'data';
|
return 'data';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCustomColumns(): array
|
public static function getCustomColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id',
|
'id',
|
||||||
|
|
@ -192,10 +192,10 @@ trait VirtualColumn
|
||||||
*/
|
*/
|
||||||
public function getColumnForQuery(string $column): string
|
public function getColumnForQuery(string $column): string
|
||||||
{
|
{
|
||||||
if (in_array($column, $this->getCustomColumns(), true)) {
|
if (in_array($column, static::getCustomColumns(), true)) {
|
||||||
return $column;
|
return $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getDataColumn() . '->' . $column;
|
return static::getDataColumn() . '->' . $column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ class MyModel extends ParentModel
|
||||||
|
|
||||||
class FooModel extends ParentModel
|
class FooModel extends ParentModel
|
||||||
{
|
{
|
||||||
public function getCustomColumns(): array
|
public static function getCustomColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id',
|
'id',
|
||||||
|
|
@ -192,7 +192,7 @@ class FooModel extends ParentModel
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataColumn(): string
|
public static function getDataColumn(): string
|
||||||
{
|
{
|
||||||
return 'virtual';
|
return 'virtual';
|
||||||
}
|
}
|
||||||
|
|
@ -215,7 +215,7 @@ class FooChild extends ParentModel
|
||||||
{
|
{
|
||||||
public $table = 'foo_childs';
|
public $table = 'foo_childs';
|
||||||
|
|
||||||
public function getCustomColumns(): array
|
public static function getCustomColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id',
|
'id',
|
||||||
|
|
@ -227,7 +227,7 @@ class BarChild extends ParentModel
|
||||||
{
|
{
|
||||||
public $table = 'bar_childs';
|
public $table = 'bar_childs';
|
||||||
|
|
||||||
public function getCustomColumns(): array
|
public static function getCustomColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id',
|
'id',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue