Laravel Events: SerializesModels Trait Causing getOriginal() Values to Show Same as Current Values #55938
Replies: 3 comments 9 replies
-
This is expected behavior. When you use a Serialize model, it only stores the model's identifier and class name. When the job is processed later, it retrieves the fresh model data from the database using that identifier. |
Beta Was this translation helpful? Give feedback.
-
@AsmitNepali
Note: use getOriginal on both |
Beta Was this translation helpful? Give feedback.
-
With latest Laravel you can get the previous and changes directly from the model. class UserObserver
{
public function updated(User $user): void
{
if ($user->isDirty('status')) {
UserStatusChangedEvent::dispatch($user, $user->getPrevious(), $user->getChanges());
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm experiencing inconsistent behavior with Laravel events when trying to access original model values for email notifications. I have two similar events, but one shows correct original vs. changed values while the other shows both values as the same.
Here's a simplified example with a User model that has a status field:
Observer
The Problem
I have two similar events:
Event A (With SerializesModels):
Event B (Without SerializesModels):
Test Case
Results
Event A (With SerializesModels):
Event B (Without SerializesModels):
Questions
Beta Was this translation helpful? Give feedback.
All reactions