Skip to content

Commit

Permalink
fix setAttribute to handle also castable and mutators and deviables
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius committed Sep 18, 2024
1 parent dc47398 commit 1d3a509
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,22 @@ public function getIgnoreExternalCreateFor(): array
*/
public function setAttribute(mixed $key, mixed $value): mixed
{
if (
$this->exists
&& \in_array($key, \array_diff($this->ignoreUpdateFor, $this->allowNonExternalUpdatesFor))
) {
if ($value !== ($attribute = $this->getAttribute($key))) {
Log::error(
'Development bug. Tried to update an ignored column ' . $key . ' on ' . \get_class($this) .
' with value: "' . $value . '" on ' . $this->getKeyName() . ' = ' . $this->getKey(
) . '. BACKTRACE: ' .
\json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3))
);
}
if (!$this->exists) {
return parent::setAttribute($key, $value);
}

$value = $attribute;
if (\in_array($key, \array_diff($this->ignoreUpdateFor, $this->allowNonExternalUpdatesFor), true)) {
Log::error(
'Development bug. Tried to update an ignored column ' . $key . ' on ' . \get_class($this) .
' with value: "' . $value . '" on ' . $this->getKeyName() . ' = ' . $this->getKey(
) . '. BACKTRACE: ' .
\json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3))
);

return $this;
}

if ($this->exists && isset($this->incrementsToRefresh[$key])) {
if (isset($this->incrementsToRefresh[$key])) {
unset($this->incrementsToRefresh[$key]);
}

Expand Down

0 comments on commit 1d3a509

Please sign in to comment.