mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 15:54:03 +00:00
Early return in the listener if data column isn't required
This commit is contained in:
parent
2d61396e54
commit
09bdf523e0
1 changed files with 5 additions and 7 deletions
|
|
@ -43,13 +43,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
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
foreach ($this->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
|
||||||
$data = $this->getAttribute(static::getDataColumn()) ?? [];
|
|
||||||
} catch (MissingAttributeException) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($data 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)) {
|
||||||
|
|
@ -114,6 +108,10 @@ trait VirtualColumn
|
||||||
return [
|
return [
|
||||||
'retrieved' => [
|
'retrieved' => [
|
||||||
function () {
|
function () {
|
||||||
|
if (($this->attributes[static::getDataColumn()] ?? null) === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Always decode after model retrieval
|
// Always decode after model retrieval
|
||||||
$this->dataEncoded = true;
|
$this->dataEncoded = true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue