Skip to content

Commit e8ce6e6

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 6b5cdf0 commit e8ce6e6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Models/BaseModel.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function getAttributeValue($key): mixed
391391
$this->incrementsToRefresh = [];
392392
}
393393

394-
$return = parent::getAttributeValue($key);
394+
$return = $this->transformModelValue($key, $this->getAttributeFromArray($key, true));
395395

396396
if (
397397
$return !== null
@@ -809,10 +809,18 @@ protected function getDirtyForUpdate(): array
809809
* @see self::getAttributeValue
810810
*
811811
* @param string $key
812+
* @param bool $mergeAllAttributesFromCachedCasts
812813
* @return mixed
813814
*/
814815
protected function getAttributeFromArray($key): mixed
815816
{
817+
if (
818+
true === (\func_get_args()[1] ?? false)
819+
&& ($this->hasGetMutator($key) || $this->hasAttributeGetMutator($key))
820+
) {
821+
return $this->getAttributes()[$key] ?? null;
822+
}
823+
816824
$this->mergeAttributesFromClassCasts($key);
817825
$this->mergeAttributesFromAttributeCasts($key);
818826

0 commit comments

Comments
 (0)