Factory-generated Carbon Object with Mutators Returns Incorrect Attribute Value Until Model is Refreshed #52200
Unanswered
green-mike
asked this question in
Q&A
Replies: 1 comment
-
Hello Mike, I tried out your testing environment, it looks to me it's because your in your and you will see the carbon object modified correctly. I'd recommend adding |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
11.15.0
PHP Version
8.3.1
Database Driver & Version
mysql Ver 8.0.35-0ubuntu0.22.04.1 for Linux on aarch64 ((Ubuntu))
Description
Issue Description
When using a factory to generate a Carbon object and using Mutators, the access attribute retrieves the Carbon object set by the factory instead of the new value set by the mutator. The value only updates correctly after a refresh from the database.
Steps to Reproduce
Expected Behavior
The date attribute should return the value set by the mutator.
Actual Behavior
The date attribute returns the Carbon object set by the factory. The value only updates correctly after refreshing the model from the database.
Analysis
Upon investigation, it appears that the
mutateAttributeMarkedAttribute
function directly uses the value in theattributeCastCache
, which retains the initial Carbon object set by the factory.framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Lines 696 to 700 in 1225a2f
Steps To Reproduce
repo: https://github.com/green-mike/laravel-issue
Beta Was this translation helpful? Give feedback.
All reactions