I have the following code where I fire an event comparing two versions of the same model.
I worked around it by manually setting a "dirty" attribute.
However, is there a way to fetch the whole original model on updated
event?
class NovaSubscriptionObserver
{
public function updated(Subscription $subscription): void
{
if ($subscription->isDirty('price_id')) {
$oldSubscription = $subscription;
$oldSubscription->price_id = $subscription->getOriginal('price_id');
SubscriptionCreatedOrUpdatedEvent::dispatch($subscription, $oldSubscription);
}
}
}
3
Answers
You can use:
You can use:
This will return the column values that your model had when it was first loaded from the database.
You can try:
This will fetch the model’s raw original attribute values.