Skip to content

Commit 1d3a509

Browse files
author
Marius
committed
fix setAttribute to handle also castable and mutators and deviables
1 parent dc47398 commit 1d3a509

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/Models/BaseModel.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,22 @@ public function getIgnoreExternalCreateFor(): array
117117
*/
118118
public function setAttribute(mixed $key, mixed $value): mixed
119119
{
120-
if (
121-
$this->exists
122-
&& \in_array($key, \array_diff($this->ignoreUpdateFor, $this->allowNonExternalUpdatesFor))
123-
) {
124-
if ($value !== ($attribute = $this->getAttribute($key))) {
125-
Log::error(
126-
'Development bug. Tried to update an ignored column ' . $key . ' on ' . \get_class($this) .
127-
' with value: "' . $value . '" on ' . $this->getKeyName() . ' = ' . $this->getKey(
128-
) . '. BACKTRACE: ' .
129-
\json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3))
130-
);
131-
}
120+
if (!$this->exists) {
121+
return parent::setAttribute($key, $value);
122+
}
132123

133-
$value = $attribute;
124+
if (\in_array($key, \array_diff($this->ignoreUpdateFor, $this->allowNonExternalUpdatesFor), true)) {
125+
Log::error(
126+
'Development bug. Tried to update an ignored column ' . $key . ' on ' . \get_class($this) .
127+
' with value: "' . $value . '" on ' . $this->getKeyName() . ' = ' . $this->getKey(
128+
) . '. BACKTRACE: ' .
129+
\json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3))
130+
);
131+
132+
return $this;
134133
}
135134

136-
if ($this->exists && isset($this->incrementsToRefresh[$key])) {
135+
if (isset($this->incrementsToRefresh[$key])) {
137136
unset($this->incrementsToRefresh[$key]);
138137
}
139138

0 commit comments

Comments
 (0)