1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 05:14:05 +00:00

make getCustomColumns() and getDataColumn() static again

This commit is contained in:
Samuel Štancl 2023-11-08 22:32:12 +01:00
parent 72de33a3d4
commit 89e00fbcd9
2 changed files with 13 additions and 13 deletions

View file

@ -42,7 +42,7 @@ trait VirtualColumn
['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);
if ($attributeHasEncryptedCastable && $this->valueEncrypted($value)) {
@ -54,7 +54,7 @@ trait VirtualColumn
$this->syncOriginalAttribute($key);
}
$this->setAttribute($this->getDataColumn(), null);
$this->setAttribute(static::getDataColumn(), null);
$this->dataEncoded = false;
}
@ -65,8 +65,8 @@ trait VirtualColumn
return;
}
$dataColumn = $this->getDataColumn();
$customColumns = $this->getCustomColumns();
$dataColumn = static::getDataColumn();
$customColumns = static::getCustomColumns();
$attributes = array_filter($this->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
// Remove data column from the attributes
@ -166,19 +166,19 @@ trait VirtualColumn
public function getCasts()
{
return array_merge(parent::getCasts(), [
$this->getDataColumn() => 'array',
static::getDataColumn() => 'array',
]);
}
/**
* Get the name of the column that stores additional data.
*/
public function getDataColumn(): string
public static function getDataColumn(): string
{
return 'data';
}
public function getCustomColumns(): array
public static function getCustomColumns(): array
{
return [
'id',
@ -192,10 +192,10 @@ trait VirtualColumn
*/
public function getColumnForQuery(string $column): string
{
if (in_array($column, $this->getCustomColumns(), true)) {
if (in_array($column, static::getCustomColumns(), true)) {
return $column;
}
return $this->getDataColumn() . '->' . $column;
return static::getDataColumn() . '->' . $column;
}
}

View file

@ -183,7 +183,7 @@ class MyModel extends ParentModel
class FooModel extends ParentModel
{
public function getCustomColumns(): array
public static function getCustomColumns(): array
{
return [
'id',
@ -192,7 +192,7 @@ class FooModel extends ParentModel
];
}
public function getDataColumn(): string
public static function getDataColumn(): string
{
return 'virtual';
}
@ -215,7 +215,7 @@ class FooChild extends ParentModel
{
public $table = 'foo_childs';
public function getCustomColumns(): array
public static function getCustomColumns(): array
{
return [
'id',
@ -227,7 +227,7 @@ class BarChild extends ParentModel
{
public $table = 'bar_childs';
public function getCustomColumns(): array
public static function getCustomColumns(): array
{
return [
'id',