1
0
Fork 0
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:
Nick Potts 2024-04-09 06:38:08 +08:00
parent 2d61396e54
commit 09bdf523e0

View file

@ -43,13 +43,7 @@ trait VirtualColumn
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
);
try {
$data = $this->getAttribute(static::getDataColumn()) ?? [];
} catch (MissingAttributeException) {
return;
}
foreach ($data 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)) {
@ -114,6 +108,10 @@ trait VirtualColumn
return [
'retrieved' => [
function () {
if (($this->attributes[static::getDataColumn()] ?? null) === null) {
return;
}
// Always decode after model retrieval
$this->dataEncoded = true;