Skip to content

Commit 703390e

Browse files
author
Pantea Marius-ciclistu
committed
POC for laravel/framework#31778 cover this case
$model = User::query()->firstOrFail(); $carbon = $model->date_time_carbon_casted; $carbon->addDay(); echo $model->col_with_get_mutator_that_depends_on_date_time_carbon_casted; // would print 'value date time' without the added day before this commit
1 parent e8ce6e6 commit 703390e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Models/ExcessiveSetOptimizerOnSaveTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,28 @@ protected function getDirtyForUpdate(): array
269269
return $this->getDirty();
270270
}
271271

272+
public function getAttributeValue($key): mixed
273+
{
274+
return $this->transformModelValue($key, $this->getAttributeFromArray($key, true));
275+
}
276+
272277
/**
273278
* Get an attribute from the $attributes array without transformation
274279
* @see self::getAttributeValue
275280
*
276281
* @param string $key
282+
* @param bool $mergeAllAttributesFromCachedCasts
277283
* @return mixed
278284
*/
279285
protected function getAttributeFromArray($key): mixed
280286
{
287+
if (
288+
true === (\func_get_args()[1] ?? false)
289+
&& ($this->hasGetMutator($key) || $this->hasAttributeGetMutator($key))
290+
) {
291+
return $this->getAttributes()[$key] ?? null;
292+
}
293+
281294
$this->mergeAttributesFromClassCasts($key);
282295
$this->mergeAttributesFromAttributeCasts($key);
283296

0 commit comments

Comments
 (0)