Skip to content

Commit 0279e60

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 daca387 commit 0279e60

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,26 @@ protected function throwMissingAttributeExceptionIfApplicable($key)
509509
*/
510510
public function getAttributeValue($key)
511511
{
512-
return $this->transformModelValue($key, $this->getAttributeFromArray($key));
512+
return $this->transformModelValue($key, $this->getAttributeFromArray($key, true));
513513
}
514514

515515
/**
516516
* Get an attribute from the $attributes array without transformation
517517
* @see self::getAttributeValue
518518
*
519519
* @param string $key
520+
* @param bool $mergeAllAttributesFromCachedCasts
520521
* @return mixed
521522
*/
522523
protected function getAttributeFromArray($key)
523524
{
525+
if (
526+
true === (\func_get_args()[1] ?? false)
527+
&& ($this->hasGetMutator($key) || $this->hasAttributeGetMutator($key))
528+
) {
529+
return $this->getAttributes()[$key] ?? null;
530+
}
531+
524532
$this->mergeAttributesFromClassCasts($key);
525533
$this->mergeAttributesFromAttributeCasts($key);
526534

0 commit comments

Comments
 (0)