Skip to content

Commit 89e00fb

Browse files
committed
make getCustomColumns() and getDataColumn() static again
1 parent 72de33a commit 89e00fb

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/VirtualColumn.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function decodeVirtualColumn(): void
4242
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
4343
);
4444

45-
foreach ($this->getAttribute($this->getDataColumn()) ?? [] as $key => $value) {
45+
foreach ($this->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
4646
$attributeHasEncryptedCastable = in_array(data_get($this->getCasts(), $key), $encryptedCastables);
4747

4848
if ($attributeHasEncryptedCastable && $this->valueEncrypted($value)) {
@@ -54,7 +54,7 @@ protected function decodeVirtualColumn(): void
5454
$this->syncOriginalAttribute($key);
5555
}
5656

57-
$this->setAttribute($this->getDataColumn(), null);
57+
$this->setAttribute(static::getDataColumn(), null);
5858

5959
$this->dataEncoded = false;
6060
}
@@ -65,8 +65,8 @@ protected function encodeAttributes(): void
6565
return;
6666
}
6767

68-
$dataColumn = $this->getDataColumn();
69-
$customColumns = $this->getCustomColumns();
68+
$dataColumn = static::getDataColumn();
69+
$customColumns = static::getCustomColumns();
7070
$attributes = array_filter($this->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
7171

7272
// Remove data column from the attributes
@@ -166,19 +166,19 @@ public function runAfterListeners($event, $halt = true)
166166
public function getCasts()
167167
{
168168
return array_merge(parent::getCasts(), [
169-
$this->getDataColumn() => 'array',
169+
static::getDataColumn() => 'array',
170170
]);
171171
}
172172

173173
/**
174174
* Get the name of the column that stores additional data.
175175
*/
176-
public function getDataColumn(): string
176+
public static function getDataColumn(): string
177177
{
178178
return 'data';
179179
}
180180

181-
public function getCustomColumns(): array
181+
public static function getCustomColumns(): array
182182
{
183183
return [
184184
'id',
@@ -192,10 +192,10 @@ public function getCustomColumns(): array
192192
*/
193193
public function getColumnForQuery(string $column): string
194194
{
195-
if (in_array($column, $this->getCustomColumns(), true)) {
195+
if (in_array($column, static::getCustomColumns(), true)) {
196196
return $column;
197197
}
198198

199-
return $this->getDataColumn() . '->' . $column;
199+
return static::getDataColumn() . '->' . $column;
200200
}
201201
}

tests/VirtualColumnTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class MyModel extends ParentModel
183183

184184
class FooModel extends ParentModel
185185
{
186-
public function getCustomColumns(): array
186+
public static function getCustomColumns(): array
187187
{
188188
return [
189189
'id',
@@ -192,7 +192,7 @@ public function getCustomColumns(): array
192192
];
193193
}
194194

195-
public function getDataColumn(): string
195+
public static function getDataColumn(): string
196196
{
197197
return 'virtual';
198198
}
@@ -215,7 +215,7 @@ class FooChild extends ParentModel
215215
{
216216
public $table = 'foo_childs';
217217

218-
public function getCustomColumns(): array
218+
public static function getCustomColumns(): array
219219
{
220220
return [
221221
'id',
@@ -227,7 +227,7 @@ class BarChild extends ParentModel
227227
{
228228
public $table = 'bar_childs';
229229

230-
public function getCustomColumns(): array
230+
public static function getCustomColumns(): array
231231
{
232232
return [
233233
'id',

0 commit comments

Comments
 (0)