Skip to content
Advertisement

Get previous attribute value in Eloquent model event

Is there a way to see the old/previous value of a model’s attribute in its saving or updating event?

eg. Is something like the following possible:

JavaScript

Advertisement

Answer

Ok, I found this quite by chance, as it’s not in the documentation at present…

There is a getOriginal() method available which returns an array of the original attribute values:

JavaScript

Be careful, prior to Laravel 7 getOriginal ignores attribute type casting.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement